[ruby-core:82145] [Ruby trunk Bug#13716][Feedback] Unexpected or undocumented (or maybe both) behaviour when mixing String#scan with named captures

From: akr@...
Date: 2017-07-24 05:31:32 UTC
List: ruby-core #82145
Issue #13716 has been updated by akr (Akira Tanaka).

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]]
```


----------------------------------------
Bug #13716: Unexpected or undocumented (or maybe both) behaviour when mixing String#scan with named captures
https://bugs.ruby-lang.org/issues/13716#change-65902

* Author: shyouhei (Shyouhei Urabe)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0dev (2017-06-22 trunk 59146) [x86_64-darwin15]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
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.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next