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"; }
In reply to regex and matching by hasnainzeenwala
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |