我有一个输入字符串,例如 "\\{\\{\\{testing}}}"
,我想要移除所有的"\"
。需要的输出结果为:"{{{testing}}}"
。
我使用以下代码来完成此操作。
string inputString = "\\{\\{\\{testing}}}";
string outputString = inputString.Replace("\\", "");
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 字符串中删除"\"
,并将所有"\\{"
替换为"{"
。
我认为问题出在正则表达式值上,即"\\\\{.*?\\\\}"
。
是否有人能让我知道应该使用什么正则表达式值来获得所需的输出。
"\\{testing}"
或"\{testing}"
作为输入传递吗?最后一个无法编译。 - J.A.I.L.i/p: "\\{testing}" - o/p: "\testing}"
i/p: "\\{\\{testing}}" - o/p: "\\{testing}}"
i/p: "\\{\\{\\{testing}}}" - o/p: "\\{\{testing}}}"
- J.A.I.L.