Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
$phone_number = "(555) 324-1233"; if ($phone_number =~/^[(]?(d{0,3})[)]?[s]?[-]?(d{3})[s]?[-]?(d{4})[s]? +[x]?(d*)$/){ #if ($phone_number =~/^(\D*\d{3}?)(\D*\d{3}?)(\D*\d{4}?)(\D*$)/){ #// we have a match, dump sub-patterns to $matches $phone = $1; #// original number $area_code = $2; #// 3-digit area code $exchange = $3; #// 3-digit exchange $number = $4; #// 4-digit number $extension = $5; #// extension print "**** $phone ** $area_code ** $exchange ** $number ** $exten +sion ***** "; }else{print "no match";}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regular Expression Help
by Roy Johnson (Monsignor) on Mar 03, 2005 at 16:54 UTC | |
|
Re: Regular Expression Help
by Tanktalus (Canon) on Mar 03, 2005 at 16:19 UTC | |
|
Re: Regular Expression Help
by ikegami (Patriarch) on Mar 03, 2005 at 16:21 UTC | |
|
Re: Regular Expression Help
by davido (Cardinal) on Mar 03, 2005 at 16:15 UTC | |
|
Re: Regular Expression Help
by prasadbabu (Prior) on Mar 03, 2005 at 16:15 UTC | |
by JediWizard (Deacon) on Mar 03, 2005 at 16:38 UTC |