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


Groups > comp.lang.python > #55801 > unrolled thread

Re: splitting by double newline

Started byIan <ian.g.kelly@gmail.com>
First post2011-02-07 10:02 -0800
Last post2011-02-07 23:02 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: splitting by double newline Ian <ian.g.kelly@gmail.com> - 2011-02-07 10:02 -0800
    Re: splitting by double newline Nikola Skoric <nick@fly.srk.fer.hr> - 2011-02-07 21:15 +0000
      Re: splitting by double newline MRAB <python@mrabarnett.plus.com> - 2011-02-07 23:02 +0000

#55801 — Re: splitting by double newline

FromIan <ian.g.kelly@gmail.com>
Date2011-02-07 10:02 -0800
SubjectRe: splitting by double newline
Message-ID<85980d81-1c01-4f71-a9da-77fb906c5358@s11g2000yqh.googlegroups.com>
On Feb 7, 10:43 am, Nikola Skoric <n...@fly.srk.fer.hr> wrote:
> Hello everybody,
>
> I'd like to split a file by double newlines, but portably. Now,
> splitting by one or more newlines is relatively easy:
>
> self.tables = re.split("[\r\n]+", bulk)
>
> But, how can I split on double newlines? I tried several approaches,
> but none worked...

self.tables = re.split(r'(?:\r\n){2,}|\r{2,}|\n{2,}', bulk)

[toc] | [next] | [standalone]


#55819

FromNikola Skoric <nick@fly.srk.fer.hr>
Date2011-02-07 21:15 +0000
Message-ID<iipne9$or9$2@nntp.amis.hr>
In reply to#55801
Dana Mon, 7 Feb 2011 10:02:05 -0800 (PST), 
Ian <ian.g.kelly@gmail.com> kaze:
> self.tables = re.split(r'(?:\r\n){2,}|\r{2,}|\n{2,}', bulk)

Thanks!

I tried without "?:", but it didn't work. Can you tell me why is it
important that group is noncapturing?


-- 
"Now the storm has passed over me
I'm left to drift on a dead calm sea
And watch her forever through the cracks in the beams
Nailed across the doorways of the bedrooms of my dreams"

[toc] | [prev] | [next] | [standalone]


#55910

FromMRAB <python@mrabarnett.plus.com>
Date2011-02-07 23:02 +0000
Message-ID<mailman.8.1297119747.6276.python-list@python.org>
In reply to#55819
On 07/02/2011 21:15, Nikola Skoric wrote:
> Dana Mon, 7 Feb 2011 10:02:05 -0800 (PST),
> Ian<ian.g.kelly@gmail.com>  kaze:
>> self.tables = re.split(r'(?:\r\n){2,}|\r{2,}|\n{2,}', bulk)
>
> Thanks!
>
> I tried without "?:", but it didn't work. Can you tell me why is it
> important that group is noncapturing?
>
The scanner uses capture groups to identify which part matched. If you
provide additional capture groups it has problems...

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web