title: How to remove escape characters from a string in JAVA
body: <p>I have input string like <code>"\\{\\{\\{testing}}}"</code> and I want to remove all <code>"\"</code>. Required o/p: <code>"{{{testing}}}"</code>. </p>
  
  <p>I am using following code to accomplish this.</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>I am passing regex as <code>"\\\\{.*?\\\\}"</code>.</p>
  
  <p>Code is working fine only for 1st occurrence of "\{" but not for all its occurrences.
  Seeing the following outputs for different inputs.</p>
  
  <ol>
  <li>i/p : <code>"\\{testing}"</code> - o/p: <code>"{testing}"</code>                    </li>
  <li>i/p : <code>"\\{\\{testing}}"</code> - o/p: <code>"{\\{testing}}"</code></li>
  <li>i/p : <code>"\\{\\{\\{testing}}}"</code> - o/p: <code>"{\\{\\{testing}}}"</code> </li>
  </ol>
  
  <p>I want <code>"\"</code> should be removed from the passed i/p string, and all <code>"\\{"</code> should be replaced with <code>"{"</code>.</p>
  
  <p>I feel the problem is with regex value i.e., <code>"\\\\{.*?\\\\}"</code>.</p>
  
  <p>Can anyone let me know what should be the regex value to the get required o/p.</p>