how to match whole word

Peng Yu PengYu.UT at gmail.com
Tue Jul 15 23:40:31 EDT 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