I want to strip '\n' and '\r' characters from a text. I use the following regex: "\\n|\\r" and use string.replaceAll(). This works fine and takes off the \n and \r chars from the string, but it also takes off characters from words starting with 'n' and 'r' with a backslash. eg: someword\new or someword\round --> someowrd\ew, someword\ound. Is there a better way to construct regex ?
sample code: (I use 4 backslashes before 'n' and 'r')
String line_sep_regex = "(\\\\n|\\\\r)";
String finalString = jsonData.toString().replaceAll(line_sep_regex, StringUtils.EMPTY);
Thank you.