how to match whole word

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


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?


	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