string search and modification

Paul Rubin http
Wed Sep 6 22:23:43 CEST 2006


Jim Britain <nomail2me at charter.net> writes:
> I would like to match [123.123.123.123] (including the qualifying
> brackets), but be able to simply return the contents, without the
> brackets.


 >>> p=r'\[((\d{1,3}\.){3}\d{1,3})\]'
 >>> m = 'dsl-kk-dynamic-013.38.22.125.touchtelindia.net [125.22.38.13] (may be'
 >>> g=re.search(p,m)
 >>> g.group(1)
'125.22.38.13'

g.group(1) matches the stuff in the first set of parens, which excludes
the square brackets.



More information about the Python-list mailing list