Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: How Greedy is Greedy: A Regex Question

by Spenser (Friar)
on Mar 18, 2007 at 23:22 UTC ( [id://605398]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://605398]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-28 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found