\b is NOT spaces<div><br></div><div><div>>>> p = re.compile(r'\sword\s')</div><div>>>> m = p.match(' word ')</div><div>>>> assert m</div><div>>>> m.group(0)</div><div>' word '</div>
<div>>>> </div><div><br></div><br><div class="gmail_quote">On Sat, May 29, 2010 at 8:34 PM, andrew cooke <span dir="ltr"><<a href="mailto:andrew@acooke.org">andrew@acooke.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
This is a bit embarassing, but I seem to be misunderstanding how \b<br>
works in regexps.<br>
<br>
Please can someone explain why the following fails:<br>
<br>
from re import compile<br>
<br>
p = compile(r'\bword\b')<br>
m = p.match(' word ')<br>
assert m<br>
<br>
My understanding is that \b matches a space at the start or end of a<br>
word, and that "word" is a word - <a href="http://docs.python.org/library/re.html" target="_blank">http://docs.python.org/library/re.html</a><br>
<br>
What am I missing here? I suspect I am doing something very stupid.<br>
<br>
Thanks,<br>
Andrew<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br></div>