Reputation: 7622
say I have this string
X,,,X,,,X,,c,,X,,,X
and I want to catch the smallest string that matches X.*c.*X
, which is X,,,X,,,X,,c,,X,,,X
the regex X.*c.*X
will catch X,,,X,,,X,,c,,X,,,X
by making the second quantifier lazy X.*c.*?X
I get X,,,X,,,X,,c,,X,,,X
but making the first quantifier lazy makes no difference X.*?c.*?X
--> X,,,X,,,X,,c,,X,,,X
How can I tell the first quantifier to also be lazy, but from the other direction?
Upvotes: 1
Views: 395
Reputation: 7622
In the example:
X[^X]*c.*?X
--> XaaaXaaaXaacXaaaX
(using negative look-around)
look for minimal XY.*c.*XY
in string: XY,,,XY,,,XY,,c,,XY,,,XY
XY((?!XY).)*c.*?XY
--> XY,,,XY,,,XY,,c,,XY,,,XY
Upvotes: 2