Re: regex matching exactly 10 digits
- From: "Dr.Ruud" <rvtol+news@xxxxxxxxxxxx>
- Date: Tue, 28 Nov 2006 17:28:39 +0100
bugbear schreef:
Paul Lalli wrote:
[attribution removed by bugbear]:
#append 1 to 10 digit fax number
$fax_num =~ s/(\d{10,10})/1$1/;
You are missing the fact that a regexp doesn't care what *else* is in
the string. You are checking only to see if the string *contains*
the pattern. "At most" does not mean that the string cannot contain
more of that token. It means that this particular piece of the
regexp will not match more than that many. You need to explicitly
check that another digit neither precedes nor follows the ten that
you've found:
Depending on the OP's data, the simpler match
/^\d{10,10}$/
may serve.
echo 9876543210 | perl -wpe '
s/^(?=[0-9]{10}$)/x/
'
x9876543210
--
Affijn, Ruud
"Gewoon is een tijger."
.
- References:
- regex matching exactly 10 digits
- From: jtbutler78@xxxxxxxxxxx
- Re: regex matching exactly 10 digits
- From: Paul Lalli
- Re: regex matching exactly 10 digits
- From: bugbear
- regex matching exactly 10 digits
- Prev by Date: Re: Expression problem
- Next by Date: Perlthrtut threadqueue example : possibly incorrect ?
- Previous by thread: Re: regex matching exactly 10 digits
- Next by thread: Re: regex matching exactly 10 digits
- Index(es):
Relevant Pages
|