java.util.regex - combining paragraphs separated by blank line

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    java.util.regex - combining paragraphs separated by blank line

    I need to write a regular expression to group lines of text separated
    by a blank line.

    Ex.

    Input:
    line1
    line2
    line3

    line 4
    line 5

    line 6

    I tried turning on the MULTILINE and DOTALL flags and used the
    following pattern:
    (.+?)^$

    which is close but prepends a newline to the 2nd and subsequent calls
    to Matcher.find().

    The first line of every paragraph is the same, if that helps.

    Regex's are cool, but frustrating....
  • hiwa

    #2
    Re: java.util.regex - combining paragraphs separated by blank line

    David <nomailplease@n omail.com> wrote in message news:<bljmpv4e5 75kq9ov5edhvsj9 60or6hj4vj@4ax. com>...[color=blue]
    > I need to write a regular expression to group lines of text separated
    > by a blank line.
    >
    > Ex.
    >
    > Input:
    > line1
    > line2
    > line3
    >
    > line 4
    > line 5
    >
    > line 6
    >
    > I tried turning on the MULTILINE and DOTALL flags and used the
    > following pattern:
    > (.+?)^$
    >
    > which is close but prepends a newline to the 2nd and subsequent calls
    > to Matcher.find().
    >
    > The first line of every paragraph is the same, if that helps.
    >
    > Regex's are cool, but frustrating....[/color]
    Regular expression that matches a blank line is ^$
    _Mastering Regular Expression_ by Friedl from O'Reilly is a good book.

    Comment

    Working...