title: strip and replace a text string with a regular expression in Java
body: <p>I am trying to strip and replace a text string in the most elegant way possible:</p>
  
  <p>With the solution I have <code>/element\s*\{"([^"]+)"\}\s*{text\s*{\s*}\s*({[^}]*})/</code></p>
  
  <pre><code>text.replaceAll("element\\s*\\{\"([^\"]+)\"}\\s*\\{text\\s*\\{\\s*}\\s*(\\{[^}]*})", "&lt;$1&gt; $2"));
  </code></pre>
  
  <p>Used on the text below:</p>
  
  <pre><code>element {"item"} {text { } {$i/child::itemno} text { } {$i/child::description} text { } element {"high_bid"} {{max($b/child::bid)}} text { }} 
  </code></pre>
  
  <p>GIVES:</p>
  
  <pre><code>&lt;item&gt; {$i/child::itemno} text { } {$i/child::description} text { } element {"high_bid"} {{max($b/child::bid)}} text { }}
  </code></pre>
  
  <p>When I'm trying to achieve:</p>
  
  <pre><code>&lt;item&gt;{$i/child::itemno}{$i/child::description}&lt;high_bid&gt;{fn:max($b/child::bid)}&lt;/high_bid&gt;&lt;/item&gt; 
  </code></pre>