title: Regex to replace substring in given xml node only
body: <p>I am trying in vain to write a regex that would only return a match if a given substring "/oem/en" (followed by a forward slash or a double quote" is found in the &lt;target&gt; XML node of a single line XLIFF code. So far here what I got but it is still matching even occurences in &lt;source&gt; nodes:</p>
  
  <pre><code>/oem/en(?=/|\")(?=.*?&lt;/target&gt;)
  </code></pre>
  
  <p>XLIFF code sample with &lt;source&gt; and &lt;target&gt; nodes:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"&gt;&lt;file product-version="1.4" original="" source-language="default" target-language="default" datatype="plaintext" category="page_content"&gt;&lt;header&gt;&lt;/header&gt;&lt;body&gt;&lt;trans-unit id="page_description" datatype="x-System.String" maxwidth="0" minwidth="0"&gt;&lt;source&gt;&lt;![CDATA[bla bla]]&gt;&lt;/source&gt;&lt;target&gt;&lt;![CDATA[translated bla bla]]&gt;&lt;/target&gt;&lt;/trans-unit&gt;&lt;trans-unit id="f55c4d88-1f2e-4ad9-aaa8-819af4ee7ee8" datatype="x-System.String" resname="PublishingPageContent" maxwidth="0" minwidth="0"&gt;&lt;source&gt;&lt;![CDATA[&lt;a href="/oem/en/link1"&gt;bla bla&lt;/a&gt;]]&gt;&lt;/source&gt;&lt;target&gt;&lt;![CDATA[&lt;a href="/oem/en/link1/&gt;translated bla bla&lt;/a&gt;]]&gt;&lt;/target&gt;&lt;/trans-unit&gt;&lt;trans-unit id="f55c4d88-1f2e-4ad9-aaa8-819af4ee7ee8" datatype="x-System.String" resname="PublishingPageContent" maxwidth="0" minwidth="0"&gt;&lt;source&gt;&lt;![CDATA[&lt;a href="/oem/en/link2"&gt;bla bla&lt;/a&gt;]]&gt;&lt;/source&gt;&lt;target&gt;&lt;![CDATA[&lt;a href="/oem/en/link2/&gt;translated bla bla&lt;/a&gt;]]&gt;&lt;/target&gt;&lt;/trans-unit&gt;&lt;/body&gt;&lt;/file&gt;&lt;/xliff&gt;
  </code></pre>
  
  <p>My approach was to try to craft an expression that would look ahead until it matches either an &lt;/source&gt; or &lt;/target&gt; and if it finds the former first, it means we are in the &lt;source&gt; node and thus it is not a match.</p>
  
  <p>Your help on this is greatly appreciated!</p>