Spyros_av Spyros_av - 14 days ago 7
Java Question

Regex - Split text into paragraphs not woking Java

Using this

i retrieve every paragraph from my text. But when there are "spaces" at the end of the text the last paragraph isn't matched .What i have to use to fix that?

Example :

I use this text :

Copyright laws are changing all over the world. Be sure to check the
copyright laws for your country before downloading or redistributing
this or any other Project Gutenberg eBook.

This header should be the first thing seen when viewing this Project
Gutenberg file. Please do not remove it.

Please read the "legal small print", and other information about the
eBook and Project Gutenberg at the bottom of this file.

look here regex101 example


I use ((?:[^\n][\n]?)+) since I have worked on my school project. It captures you all the paragraphs separated with at least one line (\n).

It works simply: Just capture everything that is not a newline.

Check the Regex101 out.