in reply to How Greedy is Greedy: A Regex Question

The practical part of this posting doesn't seem to be addressed. In the example data, the second hyperlink (i.e., the <a href...>...</a>) is lost by the expression used. Here they are again:
<a href="http://www.perlmonks.org">Perlmonks</a> is a great site, so i +s <a href="http://www.devshed.com">DevShed</a> $string =~ m%<a href="([^"]+)">(.*)</a>%;
The original poster complains that when he uses (.*?) for the second parentheses, it doesn't work properly. What should be used is (.?) without the asterisk.

-Spenser

That's Spenser, with an "s" like the detective.

Replies are listed 'Best First'.
Re^2: How Greedy is Greedy: A Regex Question
by dsb (Chaplain) on Apr 25, 2007 at 14:00 UTC
    Actually, i wasn't complaining at all. Rather inquiring as to what it is about the ? that makes the expression non-greedy back when I was still first tackling regexes. That said, I fail to see what .? would accomplish. It would match 0 or 1 non-newline characters, which has nothing to do with the OP. Perhaps you can expand on you thinking?


    dsb
    This @ISA my( $cool ) %SIG