Using Java how is it possible replace all "\n" but not ">\n" with "<br/>"?
I need it because I want add a "<br/>" if I have a new line on plain text, but not if I have HTML.
Use a negative lookbehind.
String str = "\n>\n\n";
str = str.replaceAll("(?<!>)\n", "<br />");
This will match the \n, and then backtrack a character to ensure the preceding character wasn't a >.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With