Re: Fw: Help with regex
[email protected] (Adam Turoff) Thu, 13 Aug 2009 13:23:03 -0400
| Newsgroups | perl.fwp |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Aug 13, 2009 at 12:58 PM, <[email protected]> wrote: > Anyway, some of the phone numbers look like this: > > =A0800-69-VORTEX > > ...where the user has entered alpha characters instead of numbers. My > first thought was to use a hash to do the translation, like this: > > =A0%alpha2num =3D > =A0( > =A0 =A0'A' =3D> '2', > =A0 =A0'B' =3D> '2', > =A0 =A0'C' =3D> '2', > =A0 =A0'D' =3D> '3', > =A0 =A0. > =A0 =A0. > =A0 =A0. > > ...but since the rest of the routine uses only regular expressions, I > thought that it would be nice if this type of translation could be > accomplished with a regex. $phone =3D~ s/([A-Za-z])/$alpha2num{"\U$1"}/g; Also handles the case of 650-Mr-Plow -- Adam