Search in textfiles?
Fredrik Lundh
fredrik at pythonware.com
Mon May 14 04:45:40 EDT 2001
Martin Johansson wrote:
> this code I rote, but what can be done if big letters should not be threated
> different than small letters?
convert both strings to the same case:
index = string.find(string.lower(textstring), string.lower(word))
another solution is to use case-insensitive regular expressions, but
I'm not sure it's worth the extra coding in this case.
match = re.search("(?i)" + re.escape(word), textstring)
if match:
index = match.start()
Cheers /F
More information about the Python-list
mailing list