Skip to content

Commit

Permalink
Refer named regexp captures by name
Browse files Browse the repository at this point in the history
cop idea issue: rubocop/rubocop#7754
  • Loading branch information
tejasbubane committed Mar 29, 2020
1 parent f0bf064 commit 28a4bd7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.adoc
Expand Up @@ -4385,6 +4385,23 @@ p m[1] # => "FOO"
p m[2] # => "BAR"
----

=== Refer named regexp captures by name [[refer-named-regexp-captures-by-name]]

Prefer using names to refer named regexp captures instead of numbers.

[source,ruby]
----
# bad
m = /(?<foo>FOO)(?<bar>BAR)/.match('FOOBAR')
p m[1] # => "FOO"
p m[2] # => "BAR"
# good
m = /(?<foo>FOO)(?<bar>BAR)/.match('FOOBAR')
p m[:foo] # => "FOO"
p m[:bar] # => "BAR"
----

=== No Perl Regexp Last Matchers [[no-perl-regexp-last-matchers]]

Don't use the cryptic Perl-legacy variables denoting last regexp group matches (`$1`, `$2`, etc).
Expand Down

0 comments on commit 28a4bd7

Please sign in to comment.