Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #47915

Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?)

Date 2013-06-13 09:17 +0200
From Andreas Perstinger <andipersti@gmail.com>
Subject Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?)
References <e682e1eb-1f7b-4776-82f0-11a0147947ec@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3169.1371108348.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 13.06.2013 02:59, rice.cruft@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?) rice.cruft@gmail.com - 2013-06-12 17:59 -0700
  Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?) Andreas Perstinger <andipersti@gmail.com> - 2013-06-13 09:17 +0200
    Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?) rice.stew@gmail.com - 2013-06-14 12:09 -0700
  Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?) Kevin LaTona <lists@studiosola.com> - 2013-06-13 07:42 -0700
  Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?) Kevin LaTona <lists@studiosola.com> - 2013-06-13 14:07 -0700
    Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?) rice.stew@gmail.com - 2013-06-14 12:14 -0700

csiph-web