I'm parsing a text file to extract word definitions. For example the input text file contains the following content:
di.va.gate \'di_--v*-.ga_-t\ vb pas.sim \'pas-*m\ adv : here and there : THROUGHOUT I am trying to obtain words between two literal backslashes (\ .. \). I am not able to match words between two literal backslashes using the regxp - re.compile(r'\\[^\\]*\\'). Here is my sample script: import re; #slashPattern = re.compile(re.escape(r'\\[^\\]*\\')); pattern = r'\\[^\\]*\\' slashPattern = re.compile(pattern); fdr = file( "parseinput",'r'); line = fdr.readline(); while (line != ""): if (slashPattern.match(line)): print line.rstrip() + " <-- matches pattern " + pattern else: print line.rstrip() + " <-- DOES not match pattern " + pattern line = fdr.readline(); print; ---------- The output C:\home\krishna\lang\python>python wsparsetest.py python wsparsetest.py di.va.gate \'di_--v*-.ga_-t\ vb <-- DOES not match pattern \\[^\\]*\\ pas.sim \'pas-*m\ adv : here and there : THROUGHOUT <-- DOES not match pattern \\[^\\]*\\ ----------- What should I be doing to match those literal backslashes? Thanks -- http://mail.python.org/mailman/listinfo/python-list