ignore special characters in python regex

Astan Chee astan.chee at al.com.au
Tue Jul 21 01:02:57 EDT 2009


Hi,
I'm reading text from a file (per line) and I want to do a regex using 
these lines but I want the regex to ignore any special characters and 
treat them like normal strings.
Is there a regex function that can do this?
Here is what I have so far:
fp = open('file.txt','r')
notes = fp.readlines()
fp.close()
strin = "this is what I want"
for note in notes:
     if re.search(r""+ str(note) + "",strin):
           print "Found " + str(note) + " in " + strin

Thanks for any help



More information about the Python-list mailing list