title: Converting XML tags to uppercase using a javascript regex
body: <p>I'm trying to convert XML tags to uppercase, while preserving the case of attributes and text. So for example</p>
  
  <pre><code>&lt;Mytag Category="Parent"&gt;Value1&lt;/Mytag&gt;
  </code></pre>
  
  <p>Becomes</p>
  
  <pre><code>&lt;MYTAG Category="Parent"&gt;Value1&lt;/MYTAG&gt;
  </code></pre>
  
  <p>I have a regex which matches the XML tags correctly, but the upperCase function does not seem to be working.</p>
  
  <pre><code>myXmlElement.replace(/&lt;(\/)*([a-zA-Z_0-9]+)([^&gt;]*)&gt;/g,"&lt;$1" + "$2".toUpperCase() + "$3&gt;")
  </code></pre>
  
  <p>I've also tried using <code>String.prototype.toUpperCase.apply("$2")</code>, as well as passing a function as the replace argument</p>
  
  <pre><code>myXmlElement.replace(/&lt;[\/]*([a-zA-Z_0-9]+)[^&gt;]*&gt;/g,
                      function($1,$2,$3){return &lt;$1 + $2.toUpperCase() + $3&gt;})
  </code></pre>
  
  <p>But this doesn't work, as $1,$2,$3 appear to refer to the entire matching elements ($1 = , $2 = )</p>
  
  <p>I'm sure there is something trivial I am overlooking here, can anybody help out?</p>