Following on from a previous question in which I asked:
How can I use a regular expression to match text that is between two strings, where those two
Replace the first and last (but not the middle) .*?
with (?:(?!unwanted).)*?
. (Where (?:...)
is a non-capturing group, and (?!...)
is a negative lookahead.)
However, this quickly ends up with corner cases and caveats in any real (instead of example) use, and if you would ask about what you're really doing (with real examples, even if they're simplified, instead of made up examples), you'll likely get better answers.