[英]How to use the replaceAll() method, how can I specify my regex to delete any blackslash and char right after it?
In this string below, I need to remove the backslash and the char immediately after it.在下面的这个字符串中,我需要立即删除反斜杠和后面的字符。 Code snippet below
下面的代码片段
String raw;
String s = "###\\A";)
String formatted = raw.replaceAll("\\.?", "");
System.out.println(formatted)
when I printed out the formatted, I got ###A instead of ### it appears that in the regex "\.?", the?当我打印出格式化后,我得到了###A 而不是### 它出现在正则表达式“\.?”中,? is not doing its job.
没有做它的工作。 I may be missing something here.
我可能在这里遗漏了一些东西。 My goal is to get rid of the // and the A. Any help will be appreciated
我的目标是摆脱 // 和 A。任何帮助将不胜感激
Try this REGEX \\\\[AZ]?
试试这个正则表达式
\\\\[AZ]?
String s = "###\\ZABCDE";
String formatted = s.replaceAll("\\\\[A-Z]?", "");
System.out.println(formatted);
, output , output
###ABCDE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.