Reg. Exp. question

T

TomTom

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
 
J

Janek Schleicher

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
 
C

Christophe Jacquet

TomTom said:
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}$
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top