how to match whole word

Fredrik Lundh fredrik at pythonware.com
Wed Jul 16 12:46:46 EDT 2008


Peng Yu wrote:

> I didn't read the docs and tried the following code.
> 
> regex = re.compile(r"\A" + re.escape(old_str) + r"\Z",
> opts.ignore_case and re.I or 0)
> 
> But I'm not sure why it is not working.

as the documentation says, \A and \Z matches at the beginning/end of a 
*string*, not a word.

</F>




More information about the Python-list mailing list