|
hi,,,im a new comer from perl. actually this is my first server-side scripting to deal with. i like perl because it is difficult for some begginers... i started learning perl by april 1 this year 2007.
my delimma goes this way: there is a string "fred and barney are good friends". if i want to match "fred" and "barney the pattern will be (/fred.+barney/). but then using this kind of pattern may take up some time because the pattern is using the greedy quantifier. so to compromise the speed factor involve, we will use this pattern (/fred.+?barney/).
based on my own understanding from the "Llama book", the pattern (/fred.+barney/) goes the logic this way:
NOTE: "fred and barney are good friends" <-- the string
1. the fred word from the pattern will match to the string.
2. the (.+) greedy quantifier will match the character after the word "fred" which is ' ', then 'a', until 's', the last character of the string.
3. the barney word from the pattern will try to match the character after the word fred from the string. when the character won't match, it will go to the next character saving the last character and the current character which is 'a'. then the two character will be matched (" a") to the word barney. and if still can't match the process will repeat until the character saved become (" and barney"), then the word barney will now match. finally after matching with the word barney, the pattern match will exit.
ahm guys is this logic of greedy quantifier right? or if not then what's the right thing?
another thing is about the non-greedy quantifier. based on my own understanding from the "Llama book", the pattern (/fred.+?barney/) goes the logic this way:
NOTE: "fred and barney are good friends" <-- the string
1. the fred word from the pattern will match to the string.
2. the (.+?) greedy quantifier will match the character after the word "fred" which is ' ', then exits the pattern match.
3. the barney word from the pattern will try to match the character after the word fred from the string. when the character won't match, it will go to the next character saving the last character and the current character which is 'a'. then the two character will be matched (" a") to the word barney. and if still can't match the process will repeat until the character saved become (" and barney"), then the word barney will now match. finally after matching with the word barney, the pattern match will exit.
am i right about my logic of non-greedy quantifier? or if not then what's the right thing?
oww that's it. those are my problems that needs clarification... thanks in advance guys! keep deep and dark...
From: iDLE
|
|
|
|
|
|
|
// |