|
Posted by Rik Wasmus on 10/18/07 13:30
On Thu, 18 Oct 2007 15:15:11 +0200, Steve <no.one@example.com> wrote:
>
> <davranfor@gmail.com> wrote in message
> news:1192698332.976860.15250@v23g2000prn.googlegroups.com...
>> >you had two responses...one of
>>> which (not mine, btw), is much more simply expressed than rik's
>>
>> Steve , not much more simply expressed
>>
>> "1-9" and "\d" are identical ;)
>
> uhmmmm...
>
> /^\d{1,3}(?:-\d{1,3})*$/
>
> is much more simply understood than
>
> /^([1-9][0-9]?)?[0-9](-([1-9][0-9]?)?[0-9])*$/
>
> smart ass.
Because the first hasn't got the 'starting with 0 is prohibited unless
it's only one number'-clause.
The answer without that requirement is nearly identical, and I might say
perfectly readable:
'/^ # match start of string
[0-9]{1,3} # match 1 to 3 digits
( # start subpattern
- # literal -
[0-9]{1,3} # match 1 to 3 digits
)* # match subpattern zero or more times
$ # match has to run all the way up untill the end of the string
/x'
(which in one line would result in: '/^[0-9]{1,3}(-[0-9]{1,3})*$/')
Then again I have always had an unexpainable aversion against \d, don't
know why, I just always use [0-9].
--
Rik Wasmus
[Back to original message]
|