From: Tim Slattery on
"Evertjan." <exjxw.hannivoort(a)interxnl.net> wrote:

>Tim Slattery wrote on 03 dec 2009 in comp.lang.javascript:
>
>> "tomo" <tomo(a)tomo.net> wrote:
>>
>>>Can someone please write me regex for which this string will have a
>>>match.Thanks.
>>>
>>>12.333,55
>>>12.444.444,55
>>>15.444.444.,55
>>
>> /(\d{1,3}.)*,\d{2}/
>
>No, this will not match the first two strings.

Nuts, you're right! It's going to insist on a period before the comma.

>/.*/ would do better and simpler.

But it wouldn't restrict it to digits, nor would it enforce the
groups. We could do:

/(\d{1,3}.?)*,\d{2}/

But that would allow long strings of digits without any punctuation.

--
Tim Slattery
Slattery_T(a)bls.gov
http://members.cox.net/slatteryt
From: Thomas 'PointedEars' Lahn on
Tim Slattery wrote:

> "Evertjan." <exjxw.hannivoort(a)interxnl.net> wrote:
>> Tim Slattery wrote on 03 dec 2009 in comp.lang.javascript:
>>> "tomo" <tomo(a)tomo.net> wrote:
>>>> Can someone please write me regex for which this string will have a
>>>> match.Thanks.
>>>>
>>>> 12.333,55
>>>> 12.444.444,55
>>>> 15.444.444.,55
>>>
>>> /(\d{1,3}.)*,\d{2}/
>>
>> No, this will not match the first two strings.
>
> Nuts, you're right! It's going to insist on a period before the comma.
>
>>/.*/ would do better and simpler.

Exactly :)

> But it wouldn't restrict it to digits, nor would it enforce the
> groups.

Given the specifications, it does not need to.

> We could do:
>
> /(\d{1,3}.?)*,\d{2}/
>
> But that would allow long strings of digits without any punctuation.

OK, this is probably homework, but I'll bite:

/1[25](\.[34]{3}){1,2}\.?,55/

Hopefully somebody can learn something from that ;-)


PointedEars
From: Tim Slattery on
Tim Slattery <Slattery_T(a)bls.gov> wrote:

>"Evertjan." <exjxw.hannivoort(a)interxnl.net> wrote:
>
>>Tim Slattery wrote on 03 dec 2009 in comp.lang.javascript:
>>
>>> "tomo" <tomo(a)tomo.net> wrote:
>>>
>>>>Can someone please write me regex for which this string will have a
>>>>match.Thanks.
>>>>
>>>>12.333,55
>>>>12.444.444,55
>>>>15.444.444.,55
>>>
>>> /(\d{1,3}.)*,\d{2}/
>>
>>No, this will not match the first two strings.
>
>Nuts, you're right! It's going to insist on a period before the comma.

OK, assuming OP wanted to match strings of digits broken into groups
of 3 by dots, optionally followed by a comma then two digits:

(\\d{1,3})(\\.\\d{3})*(\\,\\d{2})?

For US numeric punctuation (12,345.67):

(\\d{1,3})(\\,\\d{3})*(\\.\\d{2})?

--
Tim Slattery
Slattery_T(a)bls.gov
http://members.cox.net/slatteryt
From: Thomas 'PointedEars' Lahn on
Tim Slattery wrote:

> OK, assuming OP wanted to match strings of digits broken into groups
> of 3 by dots, optionally followed by a comma then two digits:
>
> (\\d{1,3})(\\.\\d{3})*(\\,\\d{2})?
>
> For US numeric punctuation (12,345.67):
>
> (\\d{1,3})(\\,\\d{3})*(\\.\\d{2})?

That would only work if it would be passed as content of a string value
to RegExp(). But since there is no variable part in it, RegExp() is
unnecessary, a RegExp initializer /.../ suffices (and you must not escape
the escaping backslash there).

Whether you try to escape the comma remains a mystery, too.

RTFM.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7(a)news.demon.co.uk>
From: Tim Slattery on
Thomas 'PointedEars' Lahn <PointedEars(a)web.de> wrote:

>Tim Slattery wrote:
>
>> OK, assuming OP wanted to match strings of digits broken into groups
>> of 3 by dots, optionally followed by a comma then two digits:
>>
>> (\\d{1,3})(\\.\\d{3})*(\\,\\d{2})?
>>
>> For US numeric punctuation (12,345.67):
>>
>> (\\d{1,3})(\\,\\d{3})*(\\.\\d{2})?
>
>That would only work if it would be passed as content of a string value
>to RegExp(). But since there is no variable part in it, RegExp() is
>unnecessary, a RegExp initializer /.../ suffices (and you must not escape
>the escaping backslash there).
>
>Whether you try to escape the comma remains a mystery, too.

It's a mystery to me too, but it wouldn't work without it.

--
Tim Slattery
Slattery_T(a)bls.gov
http://members.cox.net/slatteryt