Java regex: newline + white space

MatteoSp picture MatteoSp · Jun 5, 2011 · Viewed 58.8k times · Source

should be simple, but I'm going crazy with it.

Given a text like:

line number 1
line number 2
 line number 2A
line number 3
 line number 3A
 line number 3B
line number 4

I need the Java regex that deletes the line terminators then the new line begin with space, so that the sample text above become:

line number 1
line number 2line number 2A
line number 3line number 3Aline number 3B
line number 4

Answer

dantuch picture dantuch · Jun 5, 2011

yourString.replaceAll("\n ", " "); this wont help?