Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47977
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <lists@studiosola.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'yet.': 0.04; 'output': 0.05; '"""': 0.07; 'skip:\\ 20': 0.07; 'subject:help': 0.08; 'initiator': 0.09; 'parsed': 0.09; 'parsing': 0.09; 'python': 0.11; 'adjustments': 0.16; 'blocks': 0.16; 'format:': 0.16; 'from:addr:lists': 0.16; 'port,': 0.16; "r'''": 0.16; 're.compile(': 0.16; 'subject:?)': 0.16; 'subject:Problem': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; 'tcp': 0.16; 'wrote:': 0.18; 'command': 0.22; 'import': 0.22; 'skip:+ 20': 0.22; 'print': 0.22; 'skip': 0.24; 'values': 0.27; 'header:In- Reply-To:1': 0.27; 'code': 0.31; 'skip:# 10': 0.33; 'could': 0.34; 'subject: (': 0.35; 'connection': 0.35; 'something': 0.35; 'but': 0.35; 'version': 0.36; 'set.': 0.36; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'expression': 0.60; 'logged': 0.60; 'skip:2 20': 0.60; 'skip:i 50': 0.60; 'name:': 0.61; 'received:173': 0.61; 'back': 0.62; 'address': 0.63; 'header :Message-Id:1': 0.63; 'email addr:gmail.com': 0.63; 'more': 0.64; 'received:phx3.secureserver.net': 0.65; 'received:prod.phx3.secureserver.net': 0.65; 'portal': 0.68; 'default': 0.69; 'lastly,': 0.84; 'persistent': 0.84; '2013,': 0.91; 'received:173.201': 0.91 |
| Content-Type | text/plain; charset=us-ascii |
| Mime-Version | 1.0 (Mac OS X Mail 6.2 \(1499\)) |
| Subject | Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?) |
| From | Kevin LaTona <lists@studiosola.com> |
| In-Reply-To | <e682e1eb-1f7b-4776-82f0-11a0147947ec@googlegroups.com> |
| Date | Thu, 13 Jun 2013 07:42:07 -0700 |
| Content-Transfer-Encoding | quoted-printable |
| References | <e682e1eb-1f7b-4776-82f0-11a0147947ec@googlegroups.com> |
| To | python-list@python.org |
| X-Mailer | Apple Mail (2.1499) |
| X-Mailman-Approved-At | Thu, 13 Jun 2013 17:17:55 +0200 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3206.1371136676.3114.python-list@python.org> (permalink) |
| Lines | 87 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1371136676 news.xs4all.nl 15987 [2001:888:2000:d::a6]:53788 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:47977 |
Show key headers only | View raw
On Jun 12, 2013, at 5:59 PM, rice.cruft@gmail.com wrote:
> I am parsing the output of an open-iscsi command that contains several blocks of data for each data set. Each block has the format:
> Lastly, a version of this regex as a non-VERBOSE expression works as expected.. Something about re.VERBOSE... ????
Snip
With the following code tweaks in Python 2.7.2, I find it works with VERBOSE for me, but not without.
I would say the regex could still use some more adjustments yet.
-Kevin
import re
inp ="""
Target: iqn.1992-04.com.emc:vplex-000000008460319f-0000000000000007
Current Portal: 221.128.52.224:3260,7
Persistent Portal: 221.128.52.224:3260,7
**********
Interface:
**********
Iface Name: default
Iface Transport: tcp
Iface Initiatorname: iqn.1996-04.de.suse:01:7c9741b545b5
Iface IPaddress: 221.128.52.214
Iface HWaddress: <empty>
Iface Netdev: <empty>
SID: 154
iSCSI Connection State: LOGGED IN
iSCSI Session State: LOGGED_IN
Internal iscsid Session State: NO CHANGE
"""
regex = re.compile( r'''
# Target name, iqn
Target:\s+(?P<iqn>\S+)\s*
# Target portal
\s+Current\sPortal:\s*
(?P<ipaddr>\w+\.\w+\.\w+\.\w+):(?P<port>\d+),(?P<tag>\d+)
# skip lines...
[\s\S]*?
# Initiator name, iqn
Iface\s+Initiatorname:\s+(?P<initiatorName>\S+)\s*
# Initiator port, IP address
Iface\s+IPaddress:\s+(?P<initiatorIP>\S+)
# skip lines...
[\s\S]*?
# Session ID
SID:\s+(?P<SID>\d+)\s*
# Connection state
iSCSI\ +Connection\ +State:\s+(?P<connState>\w+\s*\w*)
[\s\S]*?
# Session state iSCSI
iSCSI\s+Session\s+State:\s+(?P<sessionState>\w+)\s*
# Session state Internal
Internal\s+iscsid\s+Session\s+State:.*\s+(?P<ss2>\w+\s\w+)
''', re.VERBOSE|re.MULTILINE)
myDetails = [ m.groupdict() for m in regex.finditer(inp)][0]
for k,v in myDetails.iteritems():
print k,v
#*************
If you want just the values back in the order parsed this will work for now.
for match in regex.findall(inp):
for item in range(len(match)):
print match[item]
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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