0

This is probably simple, but I can't figure this out: I need regex expression which would extract following records (Each record may span multiple lines and delimited by one or more blank lines):

TextTextTextTextTextTextText

TextTextTextTextTextTextTextTextText

(one or more blank lines)

TextTextTextTextText

TextTextText

TextTextTextTextTextTextText

(one or more blank lines)

TextTextTextTextText TextTextTextTextTextTextTextTextTextText

3
  • Either solution posted so far (Can's or Eli's) will work but you'll probably want to do a .strip() on each of the items returned, and also skip empty strings as you iterate (for cases like quadruple-or-more blank lines, leading/trailing blank lines etc). Commented Dec 25, 2009 at 15:21
  • My solution doesn't generate empty strings or leading/trailing blank lines. Commented Dec 25, 2009 at 15:31
  • 1
    @Can, sure it does, if the text starts with a newline, for example. Or if it ends with two or more newlines. It's trivial to test: re.split(r'\n\n+', '''\ntext\n\ntext\n\n''') Commented Dec 25, 2009 at 16:30

1 Answer 1

4
import re
re.split('\n\n+', text)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.