m/(?<last_name>\w+) and \w+ \g{last_name}/
This regex matches the word (i.e. \w+ characters, this does not include whitespace!) just before the ' and' and saves it under <last_name>, and which is followed by another word and the same word as what was just saved under <last_name>.
The only fixed point in this regex is the ' and', so it is easiest to start by this fixed point and see how the regex tries to match from there.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
In reply to Re: regex and matching
by CountZero
in thread regex and matching
by hasnainzeenwala
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |