Regular expression to match whole words.

Simon Brunning SBrunning at trisystems.co.uk
Wed Sep 27 16:45:55 CEST 2000


> From:	Tim Peters [SMTP:tim_one at email.msn.com]
> This is what "word-boundary assertions" are for, spelled \b.  Add this
> line:
> 
>     rePattern = r"\b(" + rePattern + r")\b"
> 
> Don't leave out rhe "r"s!  A \b is 0-width match that succeeds at the
> start
> or end of a buffer, or between a word (\w) and non-word (\W) character.
> If
> you leave out the "r"s, each \b will get treated like a backspace control
> character instead, and the result probably won't match anything!
> 
Thanks. Just the ticket.

Just as a matter if interest, what to the parentheses do, since it seems to
work fine without?

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning at trisystems.co.uk




-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list