I would like to match the numbers 123456789 and 012 using only one regex in the following strings. I am not sure how to handle all the following scenarios with a single regex:
<one><num>123456789</num><code>012</code></one>
<two><code>012</code><num>123456789</num></two>
<three num="123456789" code="012" />
<four code="012" num="123456789" />
<five code="012"><num>123456789</num></five>
<six num="123456789"><code>012</code></six>
They also don’t have to be on the same line like above, for example:
<seven>
<num>123456789</num>
<code>012</code>
</seven>
Parsing XML with regex is not a good idea. You can use XPath or xlinq. xlinq is easier. You must reference System.Xml.Linq and System.Xml and add using declerations. I wrote the code on here, not in visual studio, so there may be minor bugs…