Given a string with the following variations where {br} is a line break not a literal
- Line 1{br}Line 2
- Line 1{br}{br}Line2
- Line 1{br}{br}{br}Line 2{br}
Basically any number of line breaks between lines.
Trying to find the regex that will replace all Single and multiple occurrences (treated as one) with the characters **
Result should be
Line 1 ** Line 2
In all cases from above.
Right now I have this as a solution but I am sure the brains here have a better, smaller, easier way:
String testString = 'Line 1\r\nLine 2\r\n\r\nLine 3';
String[] tmp = testString.split('\\r|\\n');
for(integer x=0;x<tmp.size();x++){
if(tmp[x].isWhitespace()){
tmp.remove(x);
x--;
}
}
System.debug(String.join(tmp,' ** '));
Results
Line 1 ** Line 2 ** Line 3
Is there an easier way?