Project

General

Profile

Bug #13716

Unexpected or undocumented (or maybe both) behaviour when mixing String#scan with named captures

Added by shyouhei (Shyouhei Urabe) about 2 years ago. Updated 27 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0dev (2017-06-22 trunk 59146) [x86_64-darwin15]
[ruby-core:81913]

Description

Is this intentional?

[1] pry(main)> "1q2w3e4r".scan(/(\w\d)(foo){0}/)
=> [["q2", nil], ["w3", nil], ["e4", nil]]
[2] pry(main)> "1q2w3e4r".scan(/(\w\d)(?<foo>foo){0}/)
=> [[nil], [nil], [nil]]

The only difference is the capture being named.

Associated revisions

Revision bd328333
Added by jeremyevans (Jeremy Evans) 27 days ago

Document behavior when mixing named captures with parentheses [ci skip]

Fixes [Bug #13716]

History

Updated by akr (Akira Tanaka) about 2 years ago

  • Status changed from Open to Feedback

When you use a named capture, parenthesises are not considered as a capture.

So, you need to add name for all captures as:

% ruby -e 'p "1q2w3e4r".scan(/(?<bar>\w\d)(?<foo>foo){0}/)'
[["q2", nil], ["w3", nil], ["e4", nil]]

Updated by shyouhei (Shyouhei Urabe) about 2 years ago

  • Status changed from Feedback to Open

akr (Akira Tanaka) wrote:

When you use a named capture, parenthesises are not considered as a capture.

Where can I learn that restriction? I have never heard of such thing before.

#3

Updated by jeremyevans (Jeremy Evans) 27 days ago

  • Status changed from Open to Closed

Applied in changeset git|bd3283338250827e0f9e2fd1785bd1fd4151e66d.


Document behavior when mixing named captures with parentheses [ci skip]

Fixes [Bug #13716]

Also available in: Atom PDF