grouping in regular expressions.

Wolfgang Strobl Wolfgang.Strobl at gmd.de
Tue Jul 18 08:57:30 EDT 2000


kaevee at my-deja.com wrote:

>I am finding it difficult to match the ip address in the
>following line using re module.
>
>"       inet addr:192.168.0.1  Bcast:192.168.0.255  Mask:255.255.255.0"
>
>here is the expression I used.
>
>re.compile('\s+inet addr:(\d+\.\d+\.\d+\.\d+)\s+.*')
>
>I am not able to make out where i am making a mistake.

Whats wrong with

|  >>> import re
|  >>> s="       inet addr:192.168.0.1  Bcast:192.168.0.255  Mask:255.255.255.0"
|  >>> p=re.compile('\s+inet addr:(\d+\.\d+\.\d+\.\d+)\s+.*')
|  >>> p.match(s).groups()
|  ('192.168.0.1',)
|  >>> 

?


-- 
      o      (    Wolfgang.Strobl at gmd.de          (+49 2241) 14-2394
     /\        *  GMD Forschungszentrum Informationstechnik GmbH
   _`\ `_<===     Schloss Birlinghoven,           | #include
__(_)/_(_)___.-._ D-53754 Sankt Augustin, Germany | <std.disclaimer>



More information about the Python-list mailing list