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

Regex: Capturing groups inside a lookahead aren't backtracked

XMLWordPrintable

      FULL PRODUCT VERSION :
      1.8.0_144

      A DESCRIPTION OF THE PROBLEM :
      When matching against a regular expression that has a capturing group inside a lookahead, the capturing group isn't correctly backtracked.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) compile the pattern "(?=(\\d))|\\d"
      2) match against the input "4"
      3) check the value of group 1

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Group 1 should have a value of null
      ACTUAL -
      Actually, group 1 has a value of "4"

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Pattern p = Pattern.compile("(?=(\\d))|\\d");
      Matcher m = p.matcher("4");
      if(m.matches() ){
      System.out.println(m.group(1) );
      }
      ---------- END SOURCE ----------

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

              Created:
              Updated: