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

Regex: Nested capturing groups under greedy repetition aren't backtracked

XMLWordPrintable

    • Cause Known
    • generic
    • generic

      FULL PRODUCT VERSION :
      1.8.0_144

      A DESCRIPTION OF THE PROBLEM :
      When matching against a regular expression that has nested capturing groups inside a greedy repetition, the nested capturing groups aren't correctly backtracked..

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) compile the pattern "([a-z]([a-z]))+[a-z][a-z]"
      2) match against the input "abcdef"
      3) check the value of group 2

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Group 2 should have the value "d"
      ACTUAL -
      Actually, Group 2 has the value "f"

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Pattern p = Pattern.compile("([a-z]([a-z]))+[a-z][a-z]");
      Matcher m = p.matcher("abcdef");
      if(m.matches() ){
          System.out.println("Group 2 is " + m.group(2) );
      }
      ---------- END SOURCE ----------

            sherman Xueming Shen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: