capture
extracts groups matched by a regular expression pattern
(string subject, string pattern) -> list
Matches a regular expression pattern against a given subject string.
If pattern does not match given subject in its entirety, returns an empty list.
If pattern matches given subject in its entirety, a list of strings matched by capturing groups is returned.
Index 0 contains the entire input string, and subsequent indexes contain matched groups. Group indexes correspond to the sequence of opening group parentheses of capturing groups in the pattern.
If a group is optional, and is not matched by the input string, its value in the list is nil.
If a capturing group is inside a quantifier, only the last matched string is captured.
Returns nil if any argument is nil.
Parameters
| Name | Type | Description |
|---|---|---|
subject |
string | The string to match |
pattern |
string | The regular expression to match |