[Tutor] regex newbie question

Steve Willoughby steve at alchemy.com
Fri May 9 01:32:54 CEST 2008


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)*$'






More information about the Tutor mailing list