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

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

      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 lazy repetition, the nested capturing groups aren't 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 "abcd"
      3) check the value of group 2

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Group 2 should have a value of null!
      ACTUAL -
      Actually, Group 2 has a value of "d"

      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("abcd");
      if(m.matches() ){
      System.out.println("Group 2 " + m.group(2) );
      }
      ---------- END SOURCE ----------

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

              Created:
              Updated: