On 13.06.2013 02:59, rice.cr...@gmail.com wrote:
I am parsing the output of an open-iscsi command that contains
severalblocks of data for each data set. Each block has the format:
[SNIP]
I tried using \s* to swallow the whitespace between the to iSCSI
lines. No joy... However [\s\S]*? allows the regex to succeed. But that
seems to me to be overkill (I am not trying to skip lines of text here.)
Also note that I am using \ + to catch spaces between the words. On the
two problem lines, using \s+ between the label words fails.

Changing
         # Connection state
         iSCSI\ +Connection\ +State:\s+(?P<connState>\w+\s*\w*)
         [\s\S]*?    <<<<<< without this the regex fails
         # Session state
         iSCSI\ +Session\ +State:\s+(?P<sessionState>\w+)

to
        # Connection state
        iSCSI\s+Connection\s+State:\s+(?P<connState>\w+\s*\w*)\s*
        # Session state
        iSCSI\s+Session\s+State:\s+(?P<sessionState>\w+)

gives me

>>> # 'test' is the example string
>>> myDetails = [ m.groupdict() for m in regex.finditer(test)]
>>> print myDetails
[{'initiatorIP': '221.128.52.214', 'connState': 'LOGGED IN', 'SID': '154', 'ipaddr': '221.128.52.224', 'initiatorName': 'iqn.1996-04.de.suse:01:7c9741b545b5', 'sessionState': 'LOGGED_IN', 'iqn': 'iqn.1992-04.com.emc:vplex-000000008460319f-0000000000000007', 'tag': '7', 'port': '3260'}]

for your example (same for the original regex).
It looks like it works (Python 2.7.3) and there is something else breaking the regex.

Bye, Andreas
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to