Help with Regexp, \b

andrew cooke andrew at acooke.org
Sat May 29 11:04:51 EDT 2010


This is a bit embarassing, but I seem to be misunderstanding how \b
works in regexps.

Please can someone explain why the following fails:

        from re import compile

        p = compile(r'\bword\b')
        m = p.match(' word ')
        assert m

My understanding is that \b matches a space at the start or end of a
word, and that "word" is a word - http://docs.python.org/library/re.html

What am I missing here?  I suspect I am doing something very stupid.

Thanks,
Andrew



More information about the Python-list mailing list