Reg. Exp. question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TomTom

    #1

    Reg. Exp. question

    Hello !

    I think there is not a (simple) regexp that matches decimal numbers
    restricted in length, am I wrong ?

    for example:
    if we choose a length of 10 characters:
    "51,5648654 " is ok, "9515,64865 4" is not. (the comma may be anywhere)

    I can't find a regexp that matches only these character strings, what
    do you think about it ?

    thans in advance,

    Sergiogio
  • Christophe Jacquet

    #2
    Re: Reg. Exp. question

    TomTom wrote:[color=blue]
    > I think there is not a (simple) regexp that matches decimal numbers
    > restricted in length, am I wrong ?[/color]

    Hi,

    I suggest the following Perl-regexp:

    ^\d[\d,]{0,9}$

    It forbids the use of a comma as the first character. If you want to
    allow this, use the simpler regexp:

    ^[\d,]{0,10}$


    --
    Christophe Jacquet


    Comment

    • Janek Schleicher

      #3
      Re: Reg. Exp. question

      TomTom wrote at Tue, 22 Jul 2003 18:36:48 -0700:
      [color=blue]
      > I think there is not a (simple) regexp that matches decimal numbers
      > restricted in length, am I wrong ?[/color]

      I guess there will be one (but please define first what you understand as
      length in this context).
      [color=blue]
      > for example:
      > if we choose a length of 10 characters:
      > "51,5648654 " is ok, "9515,64865 4" is not. (the comma may be anywhere)[/color]

      I assume, you mean the second is wrong because it has 11 chars including
      the comma where the 1st one only has ten chars.

      A simple regexp might be:

      /\d ,\d{1,8} |
      \d\d ,\d{1,7} |
      \d{3},\d{1,6} |
      \d{4},\d{1,5} |
      \d{5},\d{1,4} |
      \d{6},\d{1,3} |
      \d{8],\d\d? |
      \d{9},\d
      /x


      Greetings,
      Janek

      Comment

      Working...