Skip to content

Recursive regex compile fails: (RegexpError) invalid group name <0> #4077

@ryannevell

Description

@ryannevell

Environment

$ jruby -v
jruby 9.1.2.0 (2.3.0) 2016-05-26 7357c8f Java HotSpot(TM) 64-Bit Server VM 25.40-b25 on 1.8.0_40-b26 +jit [darwin-x86_64]
$ uname -a
Darwin rnevell-lt.local 15.6.0 Darwin Kernel Version 15.6.0: Thu Jun 23 18:25:34 PDT 2016; root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64

Test case

$ cat test.rb

re = /a\g<0>*z/

if "aaazzz".match(re)
  puts "PASS"
else
  puts "FAIL"
  exit 1
end

Expected Behavior

MRI allows recursive regular expressions groups with the \g<0> group which is particularly useful to match balanced expressions (ie parenthesis).

Actual Behavior

Attempting to compile a regular expression with \g<0> in jruby results in:

SyntaxError: (RegexpError) invalid group name <0>: /a\g<0>*z/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions