I'm trying to view the text of HTML files in a reasonable way. After I remove all of the markup and retain only the visible text, I obtain a String that looks something like this:
\n\n\n\n \n\n\n \n\n \n Title here \n\n\n \n\n \n\n Menu Item 1 \n\n \n\n Menu Item 2 \n\n\n \n\n you get the point.
I would like to use String.replaceAll(String regex, String regex)
to replace any whitespace substring that contains more than two occurances of \n
with "\n\n"
.
Any ideas?
*Edit: *
Sorry for lack of precision. I would like the above texts changed to:
\n\nTitle here\n\nMenu Item 1\n\nMenu Item 2\n\nyou get the point.
I want any substring that is only whitespace and contains more than two newlines to be replaced by "\n\n"
.