[Tutor] Regular Expression

Que Prime queprime at gmail.com
Sat Dec 22 04:57:00 CET 2007


I need to pull the highligted data from a similar file and can't seem to get
my script to work:

Script:
import re
infile = open("filter.txt","r")
outfile = open("out.txt","w")
patt = re.compile(r"~02([\d{10}])")
for line in infile:
  m = patt.match(line)
  if m:
    outfile.write("%s\n")
infile.close()
outfile.close()


File:
200~021111001491~05070
200~021111001777~05070
200~021111001995~05090
200~021111002609~05090
200~021111002789~05070
200~012~021111004169~0
200~021111004247~05090
200~021111008623~05090
200~021111010957~05090
200~02 1111011479~05090
200~0199~021111001237~
200~021111011600~05090
200~012~02 1111022305~0
200~021111023546~05090
200~021111025427~05090
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071221/11fa842e/attachment.htm 


More information about the Tutor mailing list