hasnainzeenwala has asked for the wisdom of the Perl Monks concerning the following question:
I get the result "Flintstone". I don't understand, in the if statement, "if ($names =~ m/(?<last_name>\w+) and \w+ \g{last_name}/)" that how does it automatically match the last name, it should've matched the whole thing before "and" i.e "Fred Flintstone". Also, even when I put the * sign it still matches only "Flintstone".$names = 'Fred Flintstone and Wilma Flintstone'; if ($names =~ m/(?<last_name>\w+) and \w+ \g{last_name}/) { print "I saw $+{last_name}\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex and matching
by CountZero (Bishop) on May 27, 2011 at 18:09 UTC | |
by hasnainzeenwala (Novice) on May 28, 2011 at 06:26 UTC | |
by CountZero (Bishop) on May 28, 2011 at 06:59 UTC | |
|
Re: regex and matching
by Khen1950fx (Canon) on May 29, 2011 at 01:11 UTC |