how to match whole word

Peng Yu PengYu.UT at gmail.com
Wed Jul 16 05:40:31 CEST 2008


Hi,

The following code snippet is from /usr/bin/rpl. I would like the it
to match a word, for example, "abc" in ":abc:". But the current one
would not match "abc" in ":abc:". I tried to modify it myself. Would
you please let me know what is the corrected way to do it?

Thanks,
Peng

	if opts.whole_words:
		regex = re.compile(r"(?:(?<=\s)|^)" + re.escape(old_str) + r"(?=\s|
$)",
						   opts.ignore_case and re.I or 0)



More information about the Python-list mailing list