Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4672616

java.util.regex.Pattern incorrect handling of \G and \Z

XMLWordPrintable

    • beta
    • sparc
    • solaris_7
    • Verified

      \Z should treat a \u0085 at the end of input like a \n unless
      unix lines is enabled.

      Also

      \G should really match where the last match occurred, not where
      the next match starts.

      test cases

      import java.util.regex.*;

      public class test1 {
        public static void main(String [] args) {
          Pattern p = Pattern.compile("foo\\Z");
          Matcher m = p.matcher("foo\u0085");
          if (m.matches())
            System.out.println("matches");
          else
            System.out.println("fails");
         }
      }

      should match.

      Also

      import java.util.regex.*;

      public class test {
        public static void main(String [] args) {
          System.out.println(Pattern.compile("\\GA*")
                                    .matcher("1A2AA3")
                                    .replaceAll("X"));
         }
      }

      should print "X1A2AA3".

            mmcclosksunw Michael Mccloskey (Inactive)
            mmcclosksunw Michael Mccloskey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: