[Tutor] regex newbie question
Dick Moores
rdm at rcblue.com
Fri May 9 03:16:19 CEST 2008
At 04:32 PM 5/8/2008, Steve Willoughby wrote:
>On Thu, May 8, 2008 14:40, Dick Moores wrote:
> > At 01:30 PM 5/8/2008, Steve Willoughby wrote:
> >>On Thu, May 8, 2008 12:40, Dick Moores wrote:
> >> > But here's a chance to ask: What regex would match 2-digit strings
> >> > and 4-digit strings only?
> >>
> >>^\d\d(\d\d)?$
> >
> > Ah. And so ^\d\d(\d\d)?(\d\d)?$ matches all and only 2-, 4-, and
> > 6-digit strings. Which makes me wonder if there's a regex for ALL
> > and only strings of digits only, with an even number of digits.
>
>That would be r'^\d\d(\d\d)*$'
OK!
I bought RegexBuddy (<http://www.regexbuddy.com/>) today, which is a
big help. However, it has a comment about your regex--I think it's
saying you are wrong--tho it sure does the job for me with
VALID
12
1234
123456
12345678
1234567890
1234567890112345678901
INVALID
1
123
12345
1234567
123456789
12345678901
123456789011234567890
in matching all the valids and none of the invalids.
What say you? See <http://www.rcblue.com/Regex/all_even_number_of_digits.htm>
Thanks very much,
Dick
More information about the Tutor
mailing list