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


Groups > comp.lang.python > #58682

Re: splitting file/content into lines based on regex termination

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.014
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'subject:file': 0.07; 'string': 0.09; 'matched': 0.09; 'skip:\\ 10': 0.09; 'subject:into': 0.09; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'literals': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'omitting': 0.16; 'parentheses:': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:based': 0.16; 'wrote:': 0.18; 'split': 0.19; 'thu,': 0.19; 'import': 0.22; 'bruce': 0.22; 'separate': 0.22; 'header:User-Agent:1': 0.23; 'instance,': 0.24; 'string,': 0.24; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; "doesn't": 0.30; 'robert': 0.30; 'skip:( 20': 0.30; "i'm": 0.30; 'lines': 0.31; 'helpful.': 0.31; 'file': 0.32; 'raw': 0.33; "i'd": 0.34; 'except': 0.35; 'received:84': 0.35; 'test': 0.35; 'but': 0.35; 'i.e.': 0.36; 'method': 0.36; 'thanks': 0.36; 'should': 0.36; 'nov': 0.38; 'others.': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; 'matter': 0.61; 'kind': 0.63; 'sample': 0.67; 'header:Reply-To:1': 0.67; 'below:': 0.68; 'results': 0.69; 'reply-to:no real name:2**0': 0.71; 'reply- to:addr:python.org': 0.84; 'capture': 0.91; '2013': 0.98
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=eKcq0hZ1 c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=2LCq-pQfA8cA:10 a=szYCANicmlkA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=rVDUCw1rqEIA:10 a=pGLkceISAAAA:8 a=mkTx8DqImDSC1QMwLJwA:9 a=ETglFFePche1i4K4:21 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10
X-AUTH mrabarnett:2500
Date Thu, 07 Nov 2013 18:13:14 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.0
MIME-Version 1.0
To python-list@python.org
Subject Re: splitting file/content into lines based on regex termination
References <CAP16ngqrVAnJPxBXi8B-cAL_Q+yr47pQs1WxhvCHLM8oeVKpsg@mail.gmail.com> <CAP16ngpgdF=uYr5j8OLtBZqEmsUw9f6XPg-5Rd8HpzhBjoSpyw@mail.gmail.com>
In-Reply-To <CAP16ngpgdF=uYr5j8OLtBZqEmsUw9f6XPg-5Rd8HpzhBjoSpyw@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
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.2145.1383848001.18130.python-list@python.org> (permalink)
Lines 81
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1383848001 news.xs4all.nl 15885 [2001:888:2000:d::a6]:45419
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:58682

Show key headers only | View raw


On 07/11/2013 17:45, bruce wrote:
> update...
>
>    dat=re.compile("<br>#(\d+) / (\d+)#(\d+)#").split(s)
>
> almost works..
>
> except i get
> m = 10116#000#C S#S#100##001##DAY#Fund of Computing#Barrett,
> William#3#MWF<br>#08:00am<br>#08:50am<br>#3718 HBLL
> m = 45
> m = 58
> m = 0
> m = 10116#000#C S#S#100##002##DAY#Fund of Computing#Barrett,
> William#3#MWF<br>#09:00am<br>#09:50am<br>#3718 HBLL
> m = 9
> m = 58
> m = 0
>
> and what i want is:
> m = 10116#000#C S#S#100##001##DAY#Fund of Computing#Barrett,
> William#3#MWF<br>#08:00am<br>#08:50am<br>#3718 HBLL 45 / 58,0
> m = 10116#000#C S#S#100##002##DAY#Fund of Computing#Barrett,
> William#3#MWF<br>#09:00am<br>#09:50am<br>#3718 HBLL 9 / 58,0
>
>
> so i'd have the results of the "compile/regex process" to be added to
> the split lines
>
> thoughts/comments??
>
> thanks
>
The split method also returns what's matched in any capture groups,
i.e. "(\d+)". Try omitting the parentheses:

     dat = re.compile(r"<br>#\d+ / \d+#\d+#").split(s)

You should also be using raw string literals as above (r"..."). It
doesn't matter in this instance, but it might in others.
>
>
> On Thu, Nov 7, 2013 at 12:15 PM, bruce <badouglas@gmail.com> wrote:
>> hi.
>>
>> got a test file with the sample content listed below:
>>
>> the content is one long string, and needs to be split into separate lines
>>
>> I'm thinking the pattern to split on should be a kind of regex like::
>> <br>#45 / 58#0#
>> or
>> <br>#9 / 58#0
>> but i have no idea how to make this happen!!
>>
>> if i read the content into a buf -> s
>>
>> import re
>> dat = re.compile("what goes here??").split(s)
>>
>> --i'm not sure what goes in the compile() to get the process to work..
>>
>> thoughts/comments would be helpful.
>>
>> thanks
>>
>>
>> test dat::
>> 10116#000#C S#S#100##001##DAY#Fund of Computing#Barrett,
>> William#3#MWF<br>#08:00am<br>#08:50am<br>#3718 HBLL <br>#45 /
>> 58#0#10116#000#C S#S#100##002##DAY#Fund of Computing#Barrett,
>> William#3#MWF<br>#09:00am<br>#09:50am<br>#3718 HBLL <br>#9 /
>> 58#0#10178#000#C S#S#124##001##DAY#Computer Systems#Roper,
>> Paul#3#MWF<br>#11:00am<br>#11:50am<br>#1170 TMCB <br>#41 /
>> 145#0#10178#000#C S#S#124##002##DAY#Computer Systems#Roper,
>> Paul#3#MWF<br>#2:00pm<br>#2:50pm<br>#1170 TMCB <br>#40 /
>> 120#0#01489#002#C S#S#142##001##DAY#Intro to Computer
>> Programming#Burton, Robert <div class='instructors'>Seppi, Kevin<br
>> /></div><span
>

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


Thread

Re: splitting file/content into lines based on regex termination MRAB <python@mrabarnett.plus.com> - 2013-11-07 18:13 +0000

csiph-web