Help with Regexp, \b

andrew cooke andrew at acooke.org
Sat May 29 11:30:18 EDT 2010


On May 29, 11:24 am, Duncan Booth <duncan.bo... at invalid.invalid>
wrote:
> andrew cooke <and... at acooke.org> wrote:
> > Please can someone explain why the following fails:
>
> >         from re import compile
>
> >         p = compile(r'\bword\b')
> >         m = p.match(' word ')
> >         assert m
[...]
> You misunderstand what \b does: it doesn't match a space, it matches a 0
> length string on a boundary between a non-word and a word.
[...]

That's what I thought it did...  Then I read the docs and confused
"empty string" with "space"(!) and convinced myself otherwise.  I
think I am going senile.

Thanks very much!
Andrew



More information about the Python-list mailing list