How to match literal backslashes read from a text file using regular expressions?

George Sakkis gsakkis at
Wed Jul 13 01:53:36 CEST 2005

This should give you an idea of how to go about it (needs python 2.3 or

import re
slashPattern = re.compile(r'\\(.*?)\\')

for i,line in enumerate(file("parseinput")):
    print "line", i+1,
    match =
    if match:
        print "matched:",
        print "did not match"

#===== output =======================

line 1 matched: 'di_--v*-.ga_-t
line 2 matched: 'pas-*m



More information about the Python-list mailing list