You should do something much simpler ^_^ :
import re s = raw_input("regex : ") digs = re.compile(s) [...]
That should work :)
pierre
Dick Moores a écrit :
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 [EMAIL PROTECTED]
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
-- Pierre Barbier de Reuille
INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP Botanique et Bio-informatique de l'Architecture des Plantes TA40/PSII, Boulevard de la Lironde 34398 MONTPELLIER CEDEX 5, France
tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68 _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor