Questions tagged «replaceall»

5
String.replace所有单反斜杠和双反斜杠
我正在尝试将转换String \something\为String \\something\\using replaceAll,但是我不断遇到各种错误。我认为这是解决方案: theString.replaceAll("\\", "\\\\"); 但这给出了以下异常: java.util.regex.PatternSyntaxException: Unexpected internal error near index 1

7
用Java中的<br />替换\ n和\ r \ n
对于几种语言,已经多次询问了此信息,但我无法使其正常工作。我有这样的字符串 String str = "This is a string.\nThis is a long string."; 而且我想,以取代\n与&lt;br /&gt;使用 str = str.replaceAll("(\r\n|\n)", "&lt;br /&gt;"); 但\n不会被替换。我尝试使用此RegEx工具进行验证,但看到的结果相同。输入的字符串不匹配"(\r\n|\n)"。我究竟做错了什么 ?
68 java  regex  replaceall 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.