...is non-greedy. If you test it on this string...
abc 123 xyz xyz
abc 123 xyz. The second
xyz is not matched because of its non-greediness. But if you test it on this string...
abc abc 123 xyz
...it matches the whole string. Seems like
.*? is only non-greedy to the RIGHT of its position but not to the LEFT.
How do I make a regex like
foo.*?bar that's non-greedy in both directions?
Random test case example:
abc abc 123 xyz xyz 456 abc abc xyz 000 xyz
abc 123 xyz
You can just make sure that the first part isn't in the inner part:
If you want to avoid repeating the first part: