[Tutor] How to get user input as regex
Dick Moores
rdm at rcblue.com
Sat Apr 2 16:56:12 CEST 2005
I'm just beginning to learn regex, and am wondering how to get user input
that can be used as a regex. Of course my attempt below doesn't work, but
how should I modify it?
I'm practicing with phone.txt, which is 513 lines, each line having a
name and phone number, and some other details like an address and times.
Sorry for the dumb question.
import re
s = raw_input("regex: ")
digs = re.compile(r"s")
for line in open("data//phone.txt"):
if digs.search(line):
print line
Thanks,
Dick Moores
rdm at rcblue.com
More information about the Tutor
mailing list