String Search.

Hans Nowak wurmy at
Sat Nov 10 00:44:58 CET 2001

Adonis Vargas wrote:

> i posted a thread before asking help on how to find a specific string within
> a line of string, i unfortunately did not get too specific on what i was
> asking for. how can i do a search within a string using wildcards?
> i.e.:
> (pseudocode)
> if "*something*is*" in "something is written here": return true
> ive looked into the re module and have been to the how-to pages, but i cant
> seem to understand it.

I suppose that, for a simple case like this, you can (ab)use the fnmatch module:

>>> import fnmatch
>>> fnmatch.fnmatch('something is written here', '*something*is*')
>>> fnmatch.fnmatch('something was written here', '*something*is*')

For more sophisticated stuff, you'll really need the re module, though (or
something with similar power).


--Hans Nowak

More information about the Python-list mailing list