Jeff Johnson said:
What is the point of lazy * and lazy ? ? "Nothing" will always succeed
first, right? If not, can someone give me an example of when either of
these might be used?
I'm not sure if I got your question right, you want to know when/why to use
lazy quntifiers (*? or ??), is this correct?
You are correct, "nothing" will always succeed first, but if the subpattern
after the lazy quantifier doesn't match, the regex engine will try "more
than nothing". A common example is this one: pattern: "<div>.*</div>". If
the input sequence is:
<div>Line 1</div><div>Line 2</div><div>Line 3</div>
the pattern will match the whole text, becaue ".*" matches as much as
possible. (You might try this in Expresso or Regulator or something alike).
Using "<div>.*?</div>" will result in 3 matches, one for each "div".
Doing the same thing without lazy quantifiers is quite complex. (something
like "<div>([^<]|<[^d]|<d[^i]|<di[^v]|<div[^>\s])*</div>").
Hope this helps,
Niki