Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^4: Match variables : Beginner in perl -- webperl

by dsheroh (Prior)
on Jan 03, 2019 at 11:40 UTC ( #1227966=note: print w/replies, xml ) Need Help??

in reply to Re^3: Match variables : Beginner in perl -- webperl
in thread Match variables : Beginner in perl

Instead, use m/"(.*?)"/, which will stop matching as soon as it can.
Or, better (at least when you're going up to a single-character terminator), be more explicit about what you actually want by using a negated character class: m/"([^"]*)"/

If you want to match anything except a double-quote, tell Perl to match "anything except a double-quote" ([^"]), not "the shortest possible set of anything at all that happens to have a double-quote after it" (.*?").

Also, more pragmatically, if there's more to your regex after this part, then you could get cases where (.*?)" will still contain double-quotes in the match if that's needed to make the "more after this part" work. Because it's more explicit about not matching double-quotes, ([^"]*) will never have them in the match.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2020-06-07 03:33 GMT
Find Nodes?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?

    Results (42 votes). Check out past polls.