2 Replies Latest reply: Apr 2, 2008 4:21 AM by 800282 RSS

    replaceAll regular expression

    807601
      I have a problem with replaceAll, and I would like to know if it is eventually something wrong in java

      I try to replace the String "\E" with "\\U" and out comes U with only one slash

      if( ("a\\Ea".replaceAll("\\\\E", "\\"+"\\U")).equals("a\\Ua") == true){
                System.out.print("error");
      }

      Thanks Thomas
        • 1. Re: replaceAll regular expression
          807601
          OnlyThomas wrote:
          I have a problem with replaceAll, and I would like to know if it is eventually something wrong in java
          I really really doubt that.
          • 2. Re: replaceAll regular expression
            800282
            OnlyThomas wrote:
            I have a problem with replaceAll, and I would like to know if it is eventually something wrong in java
            ...
            No, it's your misunderstanding of regex and escaping back slashes in Strings:
            String e = "\\E";  
            System.out.println(e+" -> "+e.replaceAll("\\\\E","\\\\\\\\U"));
            System.out.println(e+" -> "+e.replace("\\E","\\\\U"));
            More info: [http://java.sun.com/docs/books/tutorial/essential/regex/]