[Pdx-pm] regex & phone numbers...

Todd Caine todd_caine at eli.net
Thu Jul 25 16:31:28 CDT 2002


Kari Chisholm wrote:

> I've conceptualized any number of highly complex and idiotic ways of
> doing this.

Me too.

sandbox:/tmp/nums[1749]> cat source
(503) 123-4567
503.123.4567
(503)-123-4567
123-4567
503 123 4567
503-123-4567
503-123-4567 ext. 69
123-4567 ext. 69
503-123-4567-mom's house
sandbox:/tmp/nums[1750]> perl -ple
'/(?:\D*(\d{3,4})\D?(?{local at n=(@n,$1)})){1,3}(?{local$r=join("-", at n)})(?{$_=$r."
".substr($_,pos($_))})/g' source
503-123-4567
503-123-4567
503-123-4567
123-4567
503-123-4567
503-123-4567
503-123-4567 ext. 69
123-4567 ext. 69
503-123-4567 mom's house




More information about the Pdx-pm-list mailing list