KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have input string like "\\{\\{\\{testing}}}" and I want to remove all "\" . Required o/p: "{{{testing}}}" . I am using following code to accomplish this. 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 am passing regex as "\\\\{.*?\\\\}" . Code is working fine only for 1st occurrence of "\{" but not for all its occurrences. Seeing the following outputs for different inputs. i/p : "\\{testing}" - o/p: "{testing}" i/p : "\\{\\{testing}}" - o/p: "{\\{testing}}" i/p : "\\{\\{\\{testing}}}" - o/p: "{\\{\\{testing}}}" I want "\" should be removed from the passed i/p string, and all "\\{" should be replaced with "{" . I feel the problem is with regex value i.e., "\\\\{.*?\\\\}" . Can anyone let me know what should be the regex value to the get required o/p.
Tags (comma-separated)
Save Edits
Cancel