grouping in regular expressions.
Carsten Gaebler
cg at schlund.de
Tue Jul 18 08:57:40 EDT 2000
kaevee at my-deja.com wrote:
> " inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0"
> re.compile('\s+inet addr:(\d+\.\d+\.\d+\.\d+)\s+.*')
> I am not able to make out where i am making a mistake.
There's no mistake. It works.
import re
line = " inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0"
regexp = re.compile('\s+inet addr:(\d+\.\d+\.\d+\.\d+)\s+.*')
match = regexp.search(line)
print match.group(1)
Carsten.
More information about the Python-list
mailing list