CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Fun With Perl: Perl Golf: Re: [unknownSym] Phone Number Input Fix Golf: Edit Log



Coderifous
journeyman

Feb 12, 2002, 12:02 PM


Views: 45609
Re: [unknownSym] Phone Number Input Fix Golf

WinkUh oh. Houston, we have a problem.

Given input with non-digit characters in between digit groups, it doesn't function properly:

111-222-4444 becomes:

111-222-4444

Becuase that \D* is matching "0 or more characters that are not-digits" So when it reaches the first digit, it has satisfied the match.

Solution: Take away the * and add the repitition modifier:

s/\D//g;s/(\d{3})(\d{3})/($1) $2-/;print;

Voila! But the credit still goes to SymAngelic

--Jim


(This post was edited by Coderifous on Feb 12, 2002, 12:03 PM)


Edit Log:
Post edited by Coderifous (journeyman) on Feb 12, 2002, 12:03 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives