[Tutor] regexp: a bit lost

Steven D'Aprano steve at pearwood.info
Sat Oct 2 02:19:21 CEST 2010

On Sat, 2 Oct 2010 01:14:27 am Alex Hall wrote:
> >> Here is my test:
> >> s=re.search(r"[\d+\s+\d+\s+\d]", l)
> >
> > Try this instead:
> >
> > re.search(r'\d+\s+\D*\d+\s+\d', l)
> Understood. My intent was to ask why my regexp would match anything
> at all.

Square brackets create a character set, so your regex tests for a string 
that contains a single character matching a digit (\d), a plus sign (+) 
or a whitespace character (\s). The additional \d + \s in the square 
brackets are redundant and don't add anything.

Steven D'Aprano

More information about the Tutor mailing list