Your regex, "/M.?c*/" will do fine at finding "Mac" or "Mc" and printing the REST of the name (rather than what the OP sought), and recall that c* matches ZERO OR MORE "c"s, meaning non-names, like Mccccc (ill-formatted roman numerals??) will match.
Also, as written, (without capturing parens) it prints:
Achallies Achallies Achounich Achounich Adam Adam Adie Adie Aindra
whereas (with slightly different use of quantifiers and a couple additional names as test cases), this appears to work as requested:
Noted also, that using $' (and friends) incurs a lot of overhead.#!C:perl/bin my @names = qw "M Mac McA Mcccccc MacAchallies McAchallies MacAchounic +h McAchounich MacAdam McAdam MacAdie McAdie MacAindra"; for(@names){ $_ =~ /(M.?c+.*)/ and print "$1\n"; } =HEAD output is: Mac McA Mcccccc MacAchallies McAchallies MacAchounich McAchounich MacAdam McAdam MacAdie McAdie MacAindra =cut
In reply to Re^2: general regex question
by ww
in thread general regex question
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |