C# regex: negative lookahead fails with the single line option
- by Sylverdrag
I am trying to figure out why a regex with negative look ahead fails when the "single line" option is turned on.
Example (simplified):
<source>Test 1</source>
<source>Test 2</source>
<target>Result 2</target>
<source>Test 3</source>
This:
<source>(?!.*<source>)(.*?)</source>(?!\s*<target)
will fail if the single line option is on, and will work if the single line option is off. For instance, this works (disables the single line option):
(?-s:<source>(?!.*<source>)(.*?)</source>(?!\s*<target))
My understanding is that the single line mode simply allows the dot "." to match new lines, and I don't see why it would affect the expression above.
Can anyone explain what I am missing here?