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: 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 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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 07/11/2013 17:45, bruce wrote: > update... > > dat=re.compile("
#(\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
#08:00am
#08:50am
#3718 HBLL > m = 45 > m = 58 > m = 0 > m = 10116#000#C S#S#100##002##DAY#Fund of Computing#Barrett, > William#3#MWF
#09:00am
#09:50am
#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
#08:00am
#08:50am
#3718 HBLL 45 / 58,0 > m = 10116#000#C S#S#100##002##DAY#Fund of Computing#Barrett, > William#3#MWF
#09:00am
#09:50am
#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"
#\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 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:: >>
#45 / 58#0# >> or >>
#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
#08:00am
#08:50am
#3718 HBLL
#45 / >> 58#0#10116#000#C S#S#100##002##DAY#Fund of Computing#Barrett, >> William#3#MWF
#09:00am
#09:50am
#3718 HBLL
#9 / >> 58#0#10178#000#C S#S#124##001##DAY#Computer Systems#Roper, >> Paul#3#MWF
#11:00am
#11:50am
#1170 TMCB
#41 / >> 145#0#10178#000#C S#S#124##002##DAY#Computer Systems#Roper, >> Paul#3#MWF
#2:00pm
#2:50pm
#1170 TMCB
#40 / >> 120#0#01489#002#C S#S#142##001##DAY#Intro to Computer >> Programming#Burton, Robert
Seppi, Kevin
> />