Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: String Matching

by Jenda (Abbot)
on Aug 15, 2012 at 07:51 UTC ( #987517=note: print w/ replies, xml ) Need Help??


in reply to Re^2: String Matching
in thread String Matching

They are greedy, but not too clever

my $str = "xaxaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; $str =~ /(a+)/; print "$1\n"; # prints "a" not "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
The quantifiers are greedy, but they refuse to let go of something they found unless forced even if they could get more someplace later.

Jenda
Enoch was right!
Enjoy the last years of Rome.


Comment on Re^3: String Matching
Download Code
Replies are listed 'Best First'.
Re^4: String Matching
by Anonymous Monk on Aug 15, 2012 at 07:54 UTC
    Um, they start from the left, stop when they find a match -- that is clever
      And predictable! I'd hate to regex in a world that wasn't predictable.
Re^4: String Matching
by AnomalousMonk (Abbot) on Aug 15, 2012 at 16:33 UTC

    I'll see you and raise you.   /(a*)/ (note * quantifier in place of +) matches, but captures nothing, not even a single 'a'.

    >perl -wMstrict -le "my $s = 'xaxaaaaa'; print qq{matched, captured '$1'} if $s =~ /(a*)/; " matched, captured ''

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2015-08-29 21:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (344 votes), past polls