match
works in a similar way to test
, but rather than returning true
if the regular expression matches any of the value, it will instead return a list of the matching values.
In the above example, we're using a regex capture group (characters surrounded by parentheses and separated by a pipe) to make sure both Ben
and ben
are matched.