|There's more than one way to do things|
Lookahead/Lookbehind Regular Expression...by mogmismo (Novice)
|on Dec 19, 2013 at 16:55 UTC||Need Help??|
mogmismo has asked for the
wisdom of the Perl Monks concerning the following question:
So, I'm trying to match, in a string, all values that are abbreviations. In this string:
"a history of u.s. coast guard aviation."
I would like the "u.s." to become "us" but not replace any other periods. Another example would be taking "M.C. Esher" and converting to "MC Esher"
So far, I can remove the middle dot, with a:$string =~ s/(?<=\w)\.(?=\w)//g;
But I can't figure out how to do a lookahead/lookbehind/lookahead/lookbehind... I've tried this, and it fails:$string =~ s/(?<=\w)\.(?=\w)\.(?=\s)//g;
Any ideas, Monks?