PerlPhi has asked for the wisdom of the Perl Monks concerning the following question:
hi,,,im a beginner on perl.actually it is my first server-side scripting language to deal with...for the reason that it is difficult for beginners.they say it is more on symbols unlike php with so many pre-defined routines, right?...but then i like to deal with the hard ones like assembly...
presently im reading the "Llama book".i started learning perl since april 1 this year.perl is great, and i think my summer is not a waste and im having a good time with it...except for one thing that i want to clarify about regular expression if you permit me.
my delima goes this way: there's a string like this "fred and barney went bowling last night", and if i want to match the words "fred" and "barney" my pattern goes this way (/fred.+barney/), right? but this pattern will take some time because i am using the greedy quantifier which is (.+), right? so to reduce the time it take to match like that one, i will use the non-greedy quantifier which is (.+?)...now my pattern will now look like this (/fred.+?barney/).
based on the book and from my own understanding the logic of the pattern (/fred.+barney/) goes this way:
was my logic on pattern match using the greedy quantifier (.+) correct? if not, then what would be the correct way to understand perl's regular expression engine on that certain pattern?
my second question is about non-greedy quantifier (.+?)...based on the book and from my own understanding the logic of the pattern (/fred.+?barney/) goes this way:
was it correct about my logic on non-greedy (.+?) quantifier? if not, then what would be the correct way to understand perl's regular expression engine on that certain pattern?
oww that's it...those are my two problems that needs answering...thanks in advance guys...keep deep and dark!From: PerlPhi
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: About Greedy and Non-Greedy Regular Expressions
by marto (Cardinal) on Apr 25, 2007 at 12:40 UTC | |
|
Re: About Greedy and Non-Greedy Regular Expressions
by RMGir (Prior) on Apr 25, 2007 at 13:40 UTC | |
|
Re: About Greedy and Non-Greedy Regular Expressions
by ww (Archbishop) on Apr 25, 2007 at 14:05 UTC | |
by RMGir (Prior) on Apr 25, 2007 at 14:36 UTC |