Hopefully simple regular expression question
Christos TZOTZIOY Georgiou
tzot at sil-tec.gr
Tue Jun 14 09:02:50 EDT 2005
On 14 Jun 2005 04:01:58 -0700, rumours say that "peterbe at gmail.com"
<peterbe at gmail.com> might have written:
>I want to match a word against a string such that 'peter' is found in
>"peter bengtsson" or " hey peter," or but in "thepeter bengtsson" or
>"hey peterbe," because the word has to stand on its own. The following
>code works for a single word:
[snip]
use \b before and after the word you search, for example:
rePeter= re.compile("\bpeter\b", re.I)
In the documentation for the re module, Subsection 4.2.1 is Regular
Expression Syntax; it'll help a lot if you read it.
Cheers.
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
More information about the Python-list
mailing list