title: Using java Pattern and Matcher, how to get first matching tag content
body: <p>I have at SoapMessage that looks like this:</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;soap:Header&gt;
      &lt;Action xmlns="http://www.w3.org/2005/08/addressing"&gt;http://service.xxx.dk/DialogModtag&lt;/Action&gt;
      &lt;MessageID xmlns="http://www.w3.org/2005/08/addressing"&gt;urn:uuid:382b4943-26e8-4698-a275-c3149d2d889e&lt;/MessageID&gt;
      &lt;To xmlns="http://www.w3.org/2005/08/addressing"&gt;http://xxx.dk/12345678&lt;/To&gt;
      &lt;RelatesTo xmlns="http://www.w3.org/2005/08/addressing"&gt;uuid:cb2320dc-c8ab-4880-94cb-2ab68129216f&lt;/RelatesTo&gt;
  &lt;/soap:Header&gt;
  &lt;soap:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-2515"&gt;
      Some content ...
  &lt;/soap:Body&gt;
  </code></pre>
  
  <p></p>
  
  <p>and I am trying to extract the contents of the &lt;Action&gt; tag within the &lt;Header&gt; tag using code like this:</p>
  
  <pre><code>Pattern PATTERN_SOAP_ACTION = 
      Pattern.compile(".*Header.*Action.*&gt;(.*)&lt;.*Action.*Header.*", Pattern.DOTALL);
  
  String text = readFile("c:\\temp\\DialogUdenBilag.xml");
  Matcher matcherSoapAction = PATTERN_SOAP_ACTION.matcher(text);
  if (matcherSoapAction.matches()) { System.out.println(matcherSoapAction.group(1)); }
  else { System.out.println("SaopAction not found"); }
  </code></pre>
  
  <p>This seems to be working OK for small soap messages. But when the soap:Body grows to +1MB, then the matches() function call takes minutes to complete.</p>
  
  <p>Any ideas for making my regex pattern more CPU friendly?</p>