On May 30, 1:30 am, andrew cooke wrote:
>
> 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.
Not necessarily. Conflating concepts like "string containing
whitespace", "string containi
On May 29, 11:24 am, Duncan Booth
wrote:
> andrew cooke 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 does
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 wrote:
> \b is NOT spaces
>
> >>> p = re.compile(r'\sword\s')
> >>> m = p.match(' word ')
> >>>
andrew cooke wrote:
> 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"
\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 wrote:
>
> This is a bit embarassing, but I seem to be misunderstanding how \b
> works in regexps.
>
> Please can someone explain wh
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 a