diff options
author | Jeremy Evans <[email protected]> | 2019-07-26 14:26:59 -0700 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2019-07-26 14:26:59 -0700 |
commit | bd3283338250827e0f9e2fd1785bd1fd4151e66d (patch) | |
tree | dd9a65b37f4b329c9bcb68d976b7e4c7d0641167 /doc/regexp.rdoc | |
parent | 5fef46ae0dedaab359f55bc3680f4278eb7da98d (diff) |
Document behavior when mixing named captures with parentheses [ci skip]
Fixes [Bug #13716]
Diffstat (limited to 'doc/regexp.rdoc')
-rw-r--r-- | doc/regexp.rdoc | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/doc/regexp.rdoc b/doc/regexp.rdoc index 9218a75b67..40c73952d6 100644 --- a/doc/regexp.rdoc +++ b/doc/regexp.rdoc @@ -238,7 +238,15 @@ where _name_ is the group name. #=> #<MatchData "ototo" vowel:"o"> *Note*: A regexp can't use named backreferences and numbered -backreferences simultaneously. +backreferences simultaneously. Also, if a named capture is used in a +regexp, then parentheses used for grouping which would otherwise result +in a unnamed capture are treated as non-capturing. + + /(\w)(\w)/.match("ab").captures # => ["a", "b"] + /(\w)(\w)/.match("ab").named_captures # => {} + + /(?<c>\w)(\w)/.match("ab").captures # => ["a"] + /(?<c>\w)(\w)/.match("ab").named_captures # => {"c"=>"a"} When named capture groups are used with a literal regexp on the left-hand side of an expression and the <tt>=~</tt> operator, the captured text is |