code: private static String translateEscaping(String pattern, char from, char to)
     {
        // if escape characters are the same OR pattern does not contain any
        // escape characters -> simply return pattern as is.
        if (from == to || (pattern.indexOf(from) < 0 && pattern.indexOf(to) < 0))
        {
           return pattern;
        }
        StringBuilder translated = new StringBuilder(pattern.length());
        boolean escaped = false;
        for (int i = 0; i < pattern.length(); i++)
        {
           if (pattern.charAt(i) == from)
           {
              if (escaped)
              {
                 translated.append(from);
                 escaped = false;
              }
              else
              {
                 escaped = true;
              }
           }
           else if (pattern.charAt(i) == to)
           {
              if (escaped)
              {
                 translated.append(to).append(to);
                 escaped = false;
              }
              else
              {
                 translated.append(to).append(to);
              }
           }
           else
           {
              if (escaped)
              {
                 translated.append(to);
                 escaped = false;
              }
              translated.append(pattern.charAt(i));
           }
        }
        return translated.toString();
     }
docs: Translates a pattern using the escape character <code>from</code> into
  a pattern using the escape character <code>to</code>.
  
  @param pattern the pattern to translate
  @param from    the currently used escape character.
  @param to      the new escape character to use.
  @return the new pattern using the escape character <code>to</code>.