mercredi 1 juillet 2015

trying to print a group from a regex match in python

am trying to print the group info from my regex match match. My script matches my regex versus line in my file, so that's working.

I have based this on the python regex tutorial btw ... I'm a python newbie (with some perl experience) :)

import re

file = open('read.txt', 'r')

p = re.compile("""
.*,\\\" 
(.*)            # use grouping here with brackets so we can fetch value with group later on
\\\"
""", re.VERBOSE)

i = 0


for line in file:
    if p.match(line):
        print p.group()   #this is the problematic group line
        i += 1

Aucun commentaire:

Enregistrer un commentaire