java.util.regex - combining paragraphs separated by blank line  
Author Message
David





PostPosted: 2003-10-26 12:39:00 Top

java-programmer, 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....
 
HGA03630





PostPosted: 2003-10-27 9:58:00 Top

java-programmer >> java.util.regex - combining paragraphs separated by blank line David <email***@***.com> wrote in message news:<email***@***.com>...
> 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....
Regular expression that matches a blank line is ^$
_Mastering Regular Expression_ by Friedl from O'Reilly is a good book.