Re: regex matching exactly 10 digits
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 28 Nov 2006 08:14:43 -0800
John W. Krahn wrote:
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;
If we're presuming that the only thing in $fax_num is the fax number
itself, then there's no reason for any checking other than the lenth:
$faxnum = "1$fax_num" if length($faxnum) == 10;
Paul Lalli
.
- References:
- regex matching exactly 10 digits
- From: jtbutler78@xxxxxxxxxxx
- Re: regex matching exactly 10 digits
- From: John W. Krahn
- regex matching exactly 10 digits
- Prev by Date: Re: literal substitution
- Next by Date: Re: literal substitution
- Previous by thread: Re: regex matching exactly 10 digits
- Next by thread: FAQ 2.1 What machines support perl? Where do I get it?
- Index(es):
Relevant Pages
|