title: Regular Expression Java XML pig
body: <p>Help please! Your few minutes could save me hours!!</p>
  
  <p>I am using PIG to get a few info.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Content
  
  &lt;Name &gt;&lt;\Name&gt; 
  &lt;Data &gt;&lt;\Data&gt;
  &lt;Data &gt;&lt;\Data&gt;
  &gt;&lt;\Content&gt;
  </code></pre>
  
  <p>So I used:</p>
  
  <pre><code>abcd_ = LOAD 'parentFolder/*' USING org.apache.pig.piggybank.storage.XMLLoader('Content') AS (content: chararray);
  </code></pre>
  
  <p>I only need a few specific info, I don't know about the possibility of:</p>
  
  <pre><code> abcd_ = LOAD 'parentFolder/*' USING org.apache.pig.piggybank.storage.XMLLoader('Content','Data') AS (content: chararray,data: chararray);
  </code></pre>
  
  <p>but I wish to avoid that. I have successfully extracted my other infos using regex after the XMLLoader except the following (just an example of possible combination of characters)</p>
  
  <pre><code>&lt;Data Name="Buffer"&gt;{&amp;quot;$type&amp;quot;System.Collections.Generic'[!#%,:()!@-;[.}&lt;\Data&gt;
  </code></pre>
  
  <p>My regular expression:</p>
  
  <pre class="lang-none prettyprint-override"><code>1. \\&lt;Data Name=\\"Buffer\\"\\&gt;\\{(.*)\\}\\&lt;\Data\\&gt; -- Unexpected character D at &lt;\Data&gt;
  2. \\&lt;Data Name=\\"Buffer\\"\\&gt;\\{(.*)\\}\\&lt;\\Data\\&gt; -- I got nothing
  3. \&lt;Data Name=\"Buffer\"\&gt;\{(.*)\}\&lt;\\Data\&gt; -- Unexpected character &lt; at \&lt;Data Name..
  4. \\&lt;Data Name=\\"Buffer\\"\\&gt;\\{(.*)\\}\\&lt;\\\Data\\&gt; -- Unexpected character D at &lt;\\\Data&gt;
  </code></pre>
  
  <p>I intended to get:</p>
  
  <pre><code>&amp;quot;$type&amp;quot;System.Collections.Generic'[!#%,:()!@-;[.
  </code></pre>
  
  <p>Edit:</p>
  
  <ol>
  <li><p>Just realized a huge mistake, \ should be /</p></li>
  <li><p>Found the answer</p>
  
  <pre><code>&lt;Data Name=\\"Buffer\\"&gt;\\{(.*)\\}&lt;/Data\\&gt;
  </code></pre></li>
  </ol>