> I am trying to grab the following string out of a text file using regular > expression (re module):
While I'm all for using regexps when they're needed, are you sure you need the overhead of regexps? f = open("foo.txt", "r") for line in f.readlines(): # if '"DcaVer"=dword:' in line: if line.startswith('"DcaVer"=dword:'): value = int(line.split(":", 1)[-1], 16) print value f.close() If you absolutely must use a regexp, import re f = open("foo", "r") r = re.compile(r'"DcaVer"=dword:([0-9a-fA-F]{7})') for line in f.readlines(): m = r.match(line) if m: value = int(m.group(1), 16) print value f.close() should do the trick for you. This assumes that each string of hex digits has seven characters. Adjust accordingly. -tim -- http://mail.python.org/mailman/listinfo/python-list