[#81492] [Ruby trunk Feature#13618] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid — normalperson@...

Issue #13618 has been reported by normalperson (Eric Wong).

12 messages 2017/06/01

[ruby-core:81505] [Ruby trunk Bug#13621] String#split returns an array longer than given limit, when passing a regexp with groups

From: cichol@...
Date: 2017-06-01 13:14:47 UTC
List: ruby-core #81505
Issue #13621 has been reported by cichol (cichol tsai).

----------------------------------------
Bug #13621: String#split returns an array longer than given limit, when passing a regexp with groups
https://bugs.ruby-lang.org/issues/13621

* Author: cichol (cichol tsai)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
The String#split documentation(http://ruby-doc.org/core-2.4.1/String.html#method-i-split) described:

> If pattern is a Regexp, str is divided where the pattern matches. Whenever the pattern matches a zero-length string, str is split into individual characters. If pattern contains groups, the respective matches will be returned in the array as well.

> If limit is a positive number, at most that number of fields will be returned (if limit is 1, the entire string is returned as the only entry in an array).

However giving a regexp with groups, split can return fields more than a given limit:

~~~ ruby
'aBa'.split(/(B)()()/, 2) # => ["a", "B", "", "", "a"]
~~~

Shouldn't it be ` ["a", "B"]` ?



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

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next