Try the following:
\b(?:\d{1,3}(?(?=[,.])[,.](?:\d{3}(?:[.,](?=\d)|\b)|(?:\b|\d{1,2}))|\b))+
It's a bit complicated to explain, but I'll try.
First, it asserts that the match must begin on a word boundary. The match
follows as a non-capturing group which may be repeated any number of times.
The match consists of:
1. 1-3 digits
2. These digits may be followed by a period or comma.
a. If they are followed by a period or a comma, they are followed by
either:
aa. Exactly 3 digits followed by a period or comma that must be
followed by a (not captured) digit, or
bb. a word boundary
b. Otherwise (not followed by a period or comma) either
aa. 1 or 2 digits, or
bb. a word boundary
3. If the initial 1-3 digits are NOT followed by a period or comma, they
must
be followed by a word boundary.
So, essentially, the rules expressed are that a match consists of a sequence
of 1-3 digits with commas between the groups of digits. However, if a group
of digits is surrounded by periods or commas, there must be exactly 3.
The trick is the quantifier on the entire group. This creates a repeating
pattern of groups of 1-3 digits followed by periods or commas. However, the
last group of digits must be followed by a word boundary, and the first
group must be preceded by a word boundary. And if a group of digits is
between periods/commas, there must be exactly 3.
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
<hellbent4u@gmail.comwrote in message
news:1175571737.035102.209140@l77g2000hsb.googlegr oups.com...
Quote:
On Mar 30, 8:59 pm, "Ben Voigt" <r...@nospam.nospamwrote:
Quote:
><hellben...@gmail.comwrote in message
>>
>news:1175139793.519997.194810@l77g2000hsb.googleg roups.com...
>>
>>
Quote:
I need aregularexpressionto be used in an ASP page which would
allow a user to enter:
>>
Quote:
1000 as well as
1,000
>>
Quote:
i.e. an amount without comma as well as with comma(for example 10,000
or 100,000 etc.)
>>
>Something like:
>>
>[0-9]+(,[0-9]{3})*
>>
>As others have said, this is only good with the (American? Imperial?)
>notation using comma for thousands grouping and point as decimal
>separator.
>>
>>
>>
>>
>>
Quote:
If anyone's aware, please let me know. I am in urgent need to use it.
>>
Quote:
Thanks and Regards,
Ankur- Hide quoted text -
>>
>- Show quoted text -
>
>
>
Hi Ben,
>
I tried your regular expression. It worked for most of the cases. But
in addition to all, it also accepts 1000,000 which it should not have.
Instead 1,000,000 is what should have been allowed. Any minor change
that can be done to the reg-ex you provided??
>
Secondly, I never posted my efforts on this thread. Here's what I have
been trying my hands on :
>
((\d{1,3})(\,\d{3})*)|(\d\d*))((\.\d{2})?)
>
It's an OR of two reg-ex, first one being the reg-ex to recognise the
number with thousand separator and second without thousand separator.
The pipe "|" doesn't seem to OR the two conditions. Any idea why is
this happening?
>
Hoping to get some headway..
>
Regards,
Ankur
>