Skip to content

Commit cfe1d6a

Browse files
author
Chad Shaffer
committed
Use Regexp.last_match(n) instead of Regexp.last_match[n]
This form behaves the same as the Perl-like regex match variables by gracefully handling nil matches
1 parent 4240e24 commit cfe1d6a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,7 +3177,7 @@ condition](#safe-assignment-in-condition).
31773177

31783178
* <a name="no-perl-regexp-last-matchers"></a>
31793179
Don't use the cryptic Perl-legacy variables denoting last regexp group
3180-
matches (`$1`, `$2`, etc). Use `Regexp.last_match[n]` instead.
3180+
matches (`$1`, `$2`, etc). Use `Regexp.last_match(n)` instead.
31813181
<sup>[[link](#no-perl-regexp-last-matchers)]</sup>
31823182

31833183
```Ruby
@@ -3188,7 +3188,7 @@ condition](#safe-assignment-in-condition).
31883188
process $1
31893189

31903190
# good
3191-
process Regexp.last_match[1]
3191+
process Regexp.last_match(1)
31923192
```
31933193

31943194
* <a name="no-numbered-regexes"></a>
@@ -3200,7 +3200,7 @@ condition](#safe-assignment-in-condition).
32003200
# bad
32013201
/(regexp)/ =~ string
32023202
...
3203-
process Regexp.last_match[1]
3203+
process Regexp.last_match(1)
32043204

32053205
# good
32063206
/(?<meaningful_var>regexp)/ =~ string

0 commit comments

Comments
 (0)