Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named capture groups cannot be accessed from MatchData in certain cases #2721

Closed
Mange opened this issue Oct 22, 2013 · 0 comments · Fixed by #2723
Closed

Named capture groups cannot be accessed from MatchData in certain cases #2721

Mange opened this issue Oct 22, 2013 · 0 comments · Fixed by #2723

Comments

@Mange
Copy link
Contributor

Mange commented Oct 22, 2013

Regexps store a lookup table for the matchdata, but only the last index is actually used to retreive the match.

Here's an example:

r = /(?:
      (?<alpha>\d)A(?<beta>\d)
    |
      (?<alpha>\d)B(?<beta>\d)
    )/x

data = r.match "1A5"
p [data[:alpha], data[:beta]]

data = r.match "1B5"
p [data[:alpha], data[:beta]]

Running this file gives different results between Rubinius and MRI:

mri-1.9.3 > ruby test.rb
["1", "5"]
["1", "5"]

mri-2.0.0 > ruby test.rb
["1", "5"]
["1", "5"]

rbx-2.1.1 > ruby test.rb
[nil, nil]
["1", "5"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant