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


Groups > comp.lang.python > #57767

Parsing multiple lines from text file using regex

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <marc@marcd.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.098
X-Spam-Evidence '*H*': 0.82; '*S*': 0.01; 'subject:text': 0.05; 'attribute': 0.07; 'nicely': 0.07; 'subject:file': 0.07; 'parsing': 0.09; 'solution,': 0.09; 'subject:using': 0.09; 'assume': 0.14; '(both': 0.16; 'delimiter': 0.16; 'delimiters': 0.16; 'escapes': 0.16; 'examples': 0.20; 'command': 0.22; 'defined': 0.27; 'tried': 0.27; 'appreciated.': 0.29; 'direction': 0.30; 'lines': 0.31; 'marc': 0.31; 'file': 0.32; 'text': 0.33; 'skip:d 20': 0.34; 'subject:from': 0.34; 'received:66': 0.35; 'possible.': 0.35; 'something': 0.35; 'but': 0.35; 'done,': 0.36; 'charset:us-ascii': 0.36; 'hi,': 0.36; 'starting': 0.37; 'skip:& 10': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'issue': 0.38; 'to:addr:python.org': 0.39; 'easy': 0.60; 'most': 0.60; 'received:unknown': 0.61; 'different': 0.65; 'between': 0.67; 'line,': 0.68; 'skip:r 30': 0.69; 'online': 0.71; 'received:199': 0.74; 'ending': 0.78; 'captures': 0.84; 'nicely.': 0.84; 'received:66.147': 0.84; 'capture': 0.91; 'banner': 0.93; 'luck': 0.93; 'message-id:@org': 0.95
From "Marc" <marc@marcd.org>
To <python-list@python.org>
Subject Parsing multiple lines from text file using regex
Date Sun, 27 Oct 2013 17:09:46 -0400
MIME-Version 1.0
Content-Type multipart/alternative; boundary="----=_NextPart_000_002E_01CED337.5A7915F0"
X-Mailer Microsoft Office Outlook 12.0
Thread-Index Ac7TF/DUd8AMBa54QhS6mHrw0a4PhQAQKRmw
Content-Language en-us
X-HR-Scan-Signature 1943b246f9bdd9b40db58a0efd4c2199
X-HR-ClamAV-Scan Clear
X-HR-SA-Score 0.0 (/)
X-HR-Status Normal-(marc@marcd.org/66.147.232.253)
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1665.1382911575.18130.python-list@python.org> (permalink)
Lines 126
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1382911575 news.xs4all.nl 15887 [2001:888:2000:d::a6]:54762
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:57767

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Hi,
I am having an issue with something that would seem to have an easy
solution, but which escapes me.  I have configuration files that I would
like to parse.  The data I am having issue with is a multi-line attribute
that has the following structure:

banner <option> <banner text delimiter>
Banner text
Banner text
Banner text
...
<banner text delimiter>

The regex 'banner\s+(\w+)\s+(.+)' captures the command nicely and
banner.group(2) captures the delimiter nicely.

My issue is that I need to capture the lines between the delimiters (both
delimiters are the same).

I have tried various permutations of 

Delimiter=banner.group(2)
re.findall(Delimiter'(.*?)'Delimiter, line, re.DOTALL|re.MULTILINE)

with no luck

Examples I have found online all assume that the starting and ending
delimiters are different and are defined directly in re.findall().  I would
like to use the original regex extracting the banner.group(2), since it is
already done, if possible.  

Any help in pointing me in the right direction would be most appreciated.

Thank you,

Marc


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


Thread

Parsing multiple lines from text file using regex "Marc" <marc@marcd.org> - 2013-10-27 17:09 -0400
  Re: Parsing multiple lines from text file using regex "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2013-10-27 22:19 +0000
    Re: Parsing multiple lines from text file using regex Roy Smith <roy@panix.com> - 2013-10-27 18:43 -0400
      Re: Parsing multiple lines from text file using regex Ben Finney <ben+python@benfinney.id.au> - 2013-10-28 10:34 +1100

csiph-web