のような入力文字列が"\\{\\{\\{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 文字列からI wantを削除し、すべて"\\{"を に置き換える必要があり"{"ます。
問題は正規表現の値、つまり"\\\\{.*?\\\\}".
get required o/p の正規表現値を教えてください。