Win XP, Python 2.5.1

I have a text file of phone numbers, which I'd like to search with a regex.

This script works fine:

import re
fstr = "\sjoe\s"
regex = "^.*" + fstr + ".*$"
p = re.compile(regex, re.I)
f = open('phone.txt', 'r')
for line in f.readlines():
    if p.search(line):
        print p.search(line).group()
f.close()

But this one, with a different 3rd line, doesn't:

import re
fstr = "\sjoe\s"
regex = "r'^.*" + fstr + ".*$'"
p = re.compile(regex, re.I)
f = open('phone.txt', 'r')
for line in f.readlines():
    if p.search(line):
        print p.search(line).group()
f.close()

Is there no way to get it to work?

Thanks,

Dick Moores
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to