|
Posted by Steve on 10/22/07 03:34
"AnrDaemon" <anrdaemon@freemail.ru> wrote in message
news:133159805.20071021150801@freemail.ru...
> Greetings, Steve.
> In reply to Your message dated Friday, October 19, 2007, 23:10:56,
>
>
>>> dgc> I need a regular expression that validate a list of numbers
>>> separated
>>> dgc> by "-" , numbers can not be greater than 999
>>>
>>>
>>> dgc> Valid examples
>>> dgc> 0
>>> dgc> 12-455-01
>>> dgc> 1-9
>>> dgc> 125-32-155-45-45
>>>
>>> dgc> Invalid examples
>>> dgc> -1
>>> dgc> 45-
>>> dgc> 1-45665456-4
>>> dgc> 12-45-
>>> dgc> -
>>>
>>> dgc> Thanks ;)
>>>
>>> Perl one:
>>> ^\d{1,3}(\-\d{1,3})*$
>
> S> wow...thanks for that! it wasn't like that was posted in two newsgroups
> 4
> S> days ago or anything...in the exact form of:
>
> S> /^\d{1,3}(?:-\d{1,3})*$/
>
> Only difference is post-processing of result produced by this RE.
> In my form You'll get set of subpatterns, in the form You referred above
> You'll get only fullstring match and no subpatterns.
> "(?: ... )" construction means grouping without storing, useful for
> in-line
> multiplication of patterns.
really? i had *no* idea! you mean, you can do that sort of thing? lol.
btw, that would be a great thing to tell the op...not me. further, you
should attempt to demonstrate that you actually know what ?: does. what you
have explained is COMPLETELY false! *grouping* does NOT mean *capturing*.
BOTH patterns GROUP. i've no idea on earth what 'multiplication of patterns'
means in regex...since multiplication is not part of any regex engine of
which i know.
to be clear to the op, ?: means that whatever is inbetween the parenthesis
will not be stored as matched output. and, since there is overhead in
capturing and given that the op ONLY wants to validate, it seems feckless to
quibble about the difference here as if yours provides a better solution. it
is the SAME regex pattern...only, yours will run slower.
> S> i suppose i should just wait till someone else answers a post and a
> couple
> S> of days later, post the exact freaking thing. the redundancy, i think,
> would
> S> just ensure that the op reeeeealy gets it.
>
> :) It was taking me longer than 2 months trying to figure out, how RE
> works
> exactly and can it be used in real life. But after that, I can't live
> without
> it.
and this means what, exactly? that you think posting identical solutions to
a problem advances the learning of the op? that's just silly.
[Back to original message]
|