[Tutor] Why doesn't this regex match???

Tim Peters tim.one@comcast.net
Sat, 09 Feb 2002 16:03:23 -0500


[Rick Pasotto]
> '[]' says 'any one *character* from the set'.

Bingo.

> '\b', '\A', and '\Z' are not characters.

Almost true:  \b is a special case.  Inside a character class, it means the
backspace character (chr(8)); outside a character class, it means
word-boundary.  Why?  Because that's what Perl decided, and Python's regexps
try to be as compatible as non-insanely possible with Perl's.

> ...
> 'word boundary' includes 'white space before and after' and 'beginning
> and end of string'.

Not so, although it's a common misunderstanding:  'word boundary' means the
character on one side is non-alphanumeric (incl. start- and end-of-string),
and the character on the other side is alphanumeric; so, in particular, \b
cannot match between whitespace characters, because there's not an
alphanumeric character on either side then.