我有输入字符串"\\{\\{\\{testing}}}",我想删除所有"\". 必需的 o/p: "{{{testing}}}"。
我正在使用以下代码来完成此操作。
protected String removeEscapeChars(String regex, String remainingValue) {
Matcher matcher = Pattern.compile(regex, Pattern.CASE_INSENSITIVE).matcher(remainingValue);
while (matcher.find()) {
String before = remainingValue.substring(0, matcher.start());
String after = remainingValue.substring(matcher.start() + 1);
remainingValue = (before + after);
}
return remainingValue;
}
我将正则表达式传递为"\\\\{.*?\\\\}".
代码仅适用于“\{”的第一次出现,但并非所有出现。查看不同输入的以下输出。
- i/p :
"\\{testing}"- o/p:"{testing}" - i/p :
"\\{\\{testing}}"- o/p:"{\\{testing}}" - i/p :
"\\{\\{\\{testing}}}"- o/p:"{\\{\\{testing}}}"
我希望"\"应该从传递的 i/p 字符串中删除,并且所有"\\{"应该替换为"{".
我觉得问题出在正则表达式值上,即"\\\\{.*?\\\\}".
谁能让我知道获取所需的o / p的正则表达式值应该是什么?