Reg. Exp. question

Discussion in 'XML' started by TomTom, Jul 23, 2003.

  1. TomTom

    TomTom Guest

    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,648654" 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
     
    TomTom, Jul 23, 2003
    #1
    1. Advertising

  2. TomTom wrote at Tue, 22 Jul 2003 18:36:48 -0700:

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


    I guess there will be one (but please define first what you understand as
    length in this context).

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


    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
     
    Janek Schleicher, Jul 23, 2003
    #2
    1. Advertising

  3. TomTom wrote:
    > I think there is not a (simple) regexp that matches decimal numbers
    > restricted in length, am I wrong ?


    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
    http://jacquetc.free.fr/
     
    Christophe Jacquet, Jul 23, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Reg exp question?

    , Jun 1, 2006, in forum: Java
    Replies:
    0
    Views:
    370
  2. laredotornado

    Java reg exp question

    laredotornado, Feb 4, 2010, in forum: Java
    Replies:
    2
    Views:
    325
    Roedy Green
    Feb 4, 2010
  3. laredotornado

    Reg exp question

    laredotornado, Aug 2, 2010, in forum: Java
    Replies:
    2
    Views:
    433
    laredotornado
    Aug 2, 2010
  4. laredotornado

    reg exp question

    laredotornado, Jan 25, 2008, in forum: Ruby
    Replies:
    2
    Views:
    86
    7stud --
    Jan 25, 2008
  5. reg exp question

    , Dec 16, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    94
    Tad McClellan
    Dec 17, 2005
Loading...

Share This Page