Help with Regexp, \b
Shashwat Anand
anand.shashwat at gmail.com
Sat May 29 11:14:33 EDT 2010
\b is NOT spaces
>>> p = re.compile(r'\sword\s')
>>> m = p.match(' word ')
>>> assert m
>>> m.group(0)
' word '
>>>
On Sat, May 29, 2010 at 8:34 PM, andrew cooke <andrew at acooke.org> wrote:
>
> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100529/01e0a5fa/attachment-0001.html>
More information about the Python-list
mailing list