Also what you are probably looking for is this I guess, >>> p = re.compile(r'\bword\b') >>> m = p.match('word word') >>> assert m >>> m.group(0) 'word'
On Sat, May 29, 2010 at 8:44 PM, Shashwat Anand <anand.shash...@gmail.com>wrote: > \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 <and...@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 >> > >
-- http://mail.python.org/mailman/listinfo/python-list