string.find for case insensitive search
Steven D'Aprano
steve at REMOVEME.cybersource.com.au
Wed Feb 7 19:38:39 EST 2007
On Wed, 07 Feb 2007 13:09:00 -0800, Don Morrison wrote:
> string.find is deprecated as per the official python documentation.
>
> take a look at the "re" module
Regular expressions are way, WAY overkill for a simple find. Just use
the string methods. Instead of this:
import string
string.find("Norwegian Blue", "Blue")
just do this:
"Norwegian Blue".find("Blue")
For case insensitive find:
"Norwegian Blue".lower().find("Blue".lower())
(or better still, turn it into a function).
--
Steven D'Aprano
More information about the Python-list
mailing list