Re: regex matching exactly 10 digits
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Tue, 28 Nov 2006 15:36:17 GMT
jtbutler78@xxxxxxxxxxx wrote:
I am having an issue trying to match exactly 10 digits. I want to
append a '1' in front of 10 digit fax numbers. Numbers longer than 10
digits leave alone. I am using \d{10,10} match at least and at most 10
digits but it still appends a 1 to international numbers. I am missing
something but I am not sure what.
#strip out unneeded chars
$fax_num =~ s/[\s()-]//g;
#append 1 to 10 digit fax number
$fax_num =~ s/(\d{10,10})/1$1/;
It looks like that instead of appending a '1' you really want to prepend a
'1'. You could do it like this:
$fax_num = "1$fax_num" if $fax_num =~ tr/0-9// == 10;
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.
- Follow-Ups:
- Re: regex matching exactly 10 digits
- From: Paul Lalli
- Re: regex matching exactly 10 digits
- References:
- regex matching exactly 10 digits
- From: jtbutler78@xxxxxxxxxxx
- regex matching exactly 10 digits
- Prev by Date: Re: regex matching exactly 10 digits
- Next by Date: Re: Expression problem
- Previous by thread: Re: regex matching exactly 10 digits
- Next by thread: Re: regex matching exactly 10 digits
- Index(es):
Relevant Pages
|