Re: regex matching exactly 10 digits



Paul Lalli wrote:
#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.

BugBear
.



Relevant Pages

  • Re: Regexp, ***= and subexpressions
    ... specified that the user's input be treated as a literal string rather than ... -exact] in cases where regexp isn't required:P ... Seems to be that regexp can't match word boundaries at "non-word" ... But now Earth has rotated and I can get back to sleep. ...
    (comp.lang.tcl)
  • Re: Regexp: Case-insensitive matching | N factorial
    ... a regexp component that matches a string of letters, ... Will match the string 'cat' anywhere it appears regardless of case. ... Javascript regular expressions have an alternative operator '|' (kind ...
    (comp.lang.javascript)
  • Re: How to get the "longest possible" match with Pythons RE module?
    ... Under most "NFA" implementation, such a regexp is ... searching a very long string that happens not to contain any matches. ... under many implementations it's very easy to end ... double-quote character at each end, and backslash escapes, ...
    (comp.lang.python)
  • Re: Regular Expression confusion
    ... > Christie Taylor wrote: ... That regexp has ... the end of the string will match, regardless of what is at the beginning ... you don't intend a capture, use instead, which is identical ...
    (comp.lang.perl.misc)
  • Re: String search vs regexp search
    ... of occurences using string & regexp. ... I wrote the code for the regexp search as well as the function ... How long is the substring? ...
    (comp.lang.python)