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?
::::::::::::::::::::::
EDIT: (?!.*) is a negative look ahead not a capturing group.
<source>(?!.*?<source>)(.*?)</source>(?!\s*<target)
will ALSO FAIL if the single line mode is on, so it doesn't look like this is a greediness issue. Try it in a Regex designer (like Expresso or Rad regex):
With single line OFF, it matches (as expected):
<source>Test 1</source>
<source>Test 3</source>
With single line ON:
<source>Test 3</source>
I don't understand why it doesn't match the first one as well: it does not contain the first negative look ahead, so it should match the expression.