PDA

View Full Version : [SOLVED] [Python] Printing re.search results



TreeFinger
July 11th, 2008, 02:07 PM
How do I get re to print the string i'm searching for that matches re.search? All I can do is print the entire line right now.

All I get is : '<_sre.SRE_Match object at 0x00A83608>'

edit.. nevermind.



if p.search(line):
m = p.search(line)
print m.group()

maximinus_uk
July 11th, 2008, 02:47 PM
One simple way is:


#!/usr/bin/python

import re

foo=re.search(r".+[W]","Hello, World")

print foo.string[foo.start():foo.end()]