aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-07-26 14:26:59 -0700
committerJeremy Evans <code@jeremyevans.net>2019-07-26 14:26:59 -0700
commitbd3283338250827e0f9e2fd1785bd1fd4151e66d (patch)
treedd9a65b37f4b329c9bcb68d976b7e4c7d0641167 /doc
parent5fef46ae0dedaab359f55bc3680f4278eb7da98d (diff)
downloadruby-bd3283338250827e0f9e2fd1785bd1fd4151e66d.tar.gz
Document behavior when mixing named captures with parentheses [ci skip]
Fixes [Bug #13716]
Diffstat (limited to 'doc')
-rw-r--r--doc/regexp.rdoc10
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