Im looking for a PCRE-regex to match lines with "1" before the first-occurrence of "xyz", so with lines like...
Anytext1 Anytext2 xyz Anytext1 xyz AnyText1 xyz
Anytext0 Anytext2 xyz AnyText1 xyz Anytext1 xyz AnyText1 xyz AnyText1 xyz
Only Line1 should be matched, is this possible?
EDIT:
If look-behinds supported variable-quantifiers, I'd just use ^(.*?xyz)(?<=.*1.*xyz).*
That could match the first xyz, then lookbehind for '1' somewhere.
String-lengths vary and '1' can be anywhere, so I cant use multiple lookbehinds with single-quantifiers.
Like if my strings were always 17-chars before xyz, I'd still need 17 different look-behinds like...
^(?:.*?xyz)(?<=.{7}1.{10}xyz).*
(matching '1' as the 8th-char, like on Line1)
^(?:.*?xyz)(?<=.{8}1.{11}xyz).*
(matching '1' as the 9th-char)
Lol, except 15 more to match all 17 positions, and my strings arent always 17-chars long anyway.
SOLUTION:
Luckily, @The Fourth Bird and @vszholobov instead offered solutions to use a negative lookahead.
Use (.)*
with a negative lookahead just before . to test that if . matches, its not 'x' followed by 'yz'.
So the solution I ended up using, looks something like...
^((?!xyz).)*1.*xyz.*
It only matches when '1' appears before the very first 'xyz' in any string.
Just insert ?: into the first group if you dont want any group consumption.. Thanks again everyone!!