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

java.util.regex.Matcher.group(int) has misleading spec

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • core-libs
    • None
    • beta
    • sparc
    • solaris_7
    • Verified

      Matcher.group(int) returns a blank string instead of null if the match was successful but the group itself did not match anything.

      So the folling piece of code

         Pattern p = Pattern.compile("ab(c*)");
         Matcher m = p.matcher("abababababa");
         m.find();
         System.out.println(m.group(1));
         
      prints a blank string instead of null.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: