text matching help
Heiko Wundram
heikowu at ceosg.de
Thu Sep 9 08:11:08 EDT 2004
Am Donnerstag, 9. September 2004 13:28 schrieb Tim Williams:
> I need to be able to match some input text to these wildcards (eg timothy
> will match tim*), * on its own is invalid, there must be text before or
> after the *.
Check out the fnmatch module (if you use simple wildcards, unix shell style,
which aren't regular expressions):
>>> import fnmatch
>>> fnmatch.fnmatch("mylittletext","my*")
True
>>> fnmatch.fnmatch("mylittletext","little*")
False
>>> fnmatch.fnmatch("mylittletext","*little*")
True
For documentation on the wildcards accepted by fnmatch.fnmatch, use
help(fnmatch)
in an interactive console window after you have imported the module.
HTH!
Heiko.
More information about the Python-list
mailing list