String Search.

Chris Liechti cliechti at gmx.net
Fri Nov 9 23:37:49 CET 2001


"Adonis Vargas" <deltapigz at telocity.com> wrote in
news:IwZG7.442$EL1.358521 at newsrump.sjc.telocity.net: 

> 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

return re.search("something.*is", "something is written here") is not None

it returns a match object if the string was found or None otherwise.
you dont need to care about the match object in your case but it can
become handy when you add groups in the regular expression.

the "." stands for "any character" and "*" for any number of the preceding 
object, so ".*" matches for a string of any length with any character in it

you don't need the wildcard at the beginning or at the end as regexps have 
special characters for start ("^") and end ("$").

> ive looked into the re module and have been to the how-to pages, but i
> cant seem to understand it.

at first regular expressions may look strange but when you get used to them 
you won't understand how you could have lived so long without them ;-)

chris

> any help would greatly be appreciated.
> 
> Adonis
> 


-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list