Re: Regex Help

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Alexey Smirnov wrote:
On Mar 1, 4:29 pm, "G" <g...@xxxxxxxxxx> wrote:
Hello,

I have a REGEX validator which checks for DIGITS ONLY, 10 or 11 digits in
length. The pattern is:#

^\d{10,11}$

I would like to enhance this pattern so in addition to only digits, and
string must be 10 or 11 characters in length, - I would like the first
character to be a 0, and the second character must NEVER be a 0.

Matches:
0100000000
01234567890
0101010101

Non Matches:
1000000000
0010000000
1010101010

Any regex pro's here able to assist?

Kind Regards,

Gary.

^0(?!0)\d{8,9}$


That would be:

^0(?!0)\d{9,10}$

as the look-ahead doesn't consume the character. :)

Here's another way of writing it, perhaps a bit more straight forward:

^0[1-9]\d{8,9}$

--
Göran Andersson
_____
http://www.guffa.com
.



Relevant Pages

  • modulo encrypt problem
    ... I am trying to get an extremely simple character string encryption function ... The pattern to be encrypted is a string of ASCII numeric digits. ...
    (comp.lang.c)
  • Re: Regex Help
    ... I have a REGEX validator which checks for DIGITS ONLY, ... I would like to enhance this pattern so in addition to only digits, ... character to be a 0, and the second character must NEVER be a 0. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Effective/Proper use of "regular expressions"
    ... parenthesized elements in your regular expression, ... from the set (unless the first character in the bracket expression is ... The range 0-9 is the set of all digits, ... a literal period followed by one or more digits". ...
    (comp.lang.tcl)
  • Re: inputting the ephemerides (SOLUTION!)
    ... the user manual input of control data, or the use of a control record, ... Somewhere along the way, I've lost the last float, which Terence calls F3. ... C STOPS ON TRAILING BLANK OR CHARACTER ... C NOW ONLY DIGITS ...
    (comp.lang.fortran)
  • Re: inputting the ephemerides (SOLUTION!)
    ... Defining the rules for field parsing has to match all the ... these are placed in the character string CWK). ... string stops the parsing and GOs to statement 7. ... Here the string CWK of sign, digits and a decimal point if present are ...
    (comp.lang.fortran)