Named Regex Captures Are Assigned To Variables
Both String
and Regexp
include the =~
operator as a way of checking if a string and a regex match.
When the Regexp
version of =~
with named capture groups, those named captures will be auto-assigned as local variables.
Here is a regex that includes a named capture: (?<id>\d+)
. The parentheses define the capture area and the ?<id>
specifies that whatever follows in the capture will be named id
.
After the match operator (=~
) runs in the first line, the local variable id
gets assigned to whatever it matches in the corresponding string.
PreviousMocking Requests With Partial URIs Using RegexNextNavigate Back In The Browser With Capybara
Last updated