0

I have this XML-structure where I would like to match the individual data-elements elements that have the ###DoNotUse### string inside.

In the example, it should match the data elements C and E.

But my RegEx also matches all data-elements before the matches that I require, meaning A+B+C instead of just C, and D+E instead of just E.

I appreciate your help very much.

My RegEx is:

<data(.*?)###DoNotUse###(.*?)</data>

The example data is:

<data name="A">
    <value>A</value>
<comment>Bla Bla</comment>
</data>
<data name="B">
    <value>B</value>
</data>
<data name="C">
    <value>###DoNotUse###</value>
    <comment>Bla Bla</comment>
</data>
<data name="D">
    <value>D</value>
    <comment>Bla Bla</comment>
</data>
<data name="E">
    <value>###DoNotUse###</value>
</data>
Lee Mac
  • 15,615
  • 6
  • 32
  • 80
Thomas
  • 3
  • 1

1 Answers1

0

You are looking for :

(?s)<data name="([^"]*)">(?:(?!data).)*DoNotUse

The (?s) is for single line mode. You can find the demonstration and explanations HERE: DEMO

Onyambu
  • 67,392
  • 3
  • 24
  • 53
  • That seems to do the trick after some minor modification and points me into the right direction. Thank you very much! – Thomas Nov 16 '18 at 07:36