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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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


Feb 12, 2002, 12:02 PM

Views: 86989
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:


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


(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