The following regex finds text between substrings FTW and ODP.
/FTW(((?!FTW|ODP).)+)ODP+/
What does the (?!
…)
do?
regexregex-lookarounds
The following regex finds text between substrings FTW and ODP.
/FTW(((?!FTW|ODP).)+)ODP+/
What does the (?!
…)
do?
Best Answer
(?!regex)
is a zero-width negative lookahead. It will test the characters at the current cursor position and forward, testing that they do NOT match the supplied regex, and then return the cursor back to where it started.The whole regexp:
So - Hunt for
FTW
, then capture while looking forODP+
to end our string. Also ensure that the data betweenFTW
andODP+
doesn't containFTW
orODP