1 Reply Latest reply on Oct 31, 2007 7:48 PM by 807603

    Replace to  consolidate two chars into one

      My program receives code with some regex escape sequences built into the code as two ascii chars. I would like to consolidate those two chars into a single escape sequence.

      String testString = "Message\\nline break,\\n\\tline break and tab";

      // this shows what I want, but it is hard coded for only two conditions.
      System.out.println(testString.replaceAll("\\\\n", "\n").replaceAll("\\\\t", "\t"));

      // What I would like to do is something like this, but I either end up escaping the group lookup, generate two chars, or create a parser error.
      System.out.println(testString.replaceAll("\\\\(.)", "\$1"));

      Are there any good ways that Regex can be used to create an escape sequence from a group match?