regexp {utilitiesR} | R Documentation |
Extract captured groups in a (Perl) regex.
regexp(pattern, text, ...)
pattern |
the regex (in Perl), with capturing brackets, possibly named. |
text |
the string or character string to test the regex against |
... |
If there are no capturing groups in the pattern, an error is thrown. If there are capturing groups but a group simply does not have a match in the string, that entry is the empty string "".
A matrix with the same number of rows as 'text' and one column per captured group. If named captured groups are used (e.g. '(?<num>[0-9]+)'), the names will be the column names.
This is essentially stringr's str_matches but avoids me loading stringr in.
gregexp
for the same thing, but using the
'g' flag (yielding much more unwieldy output)
regexp('^(?<greeting>.+?)[, ]+(?<target>.+)$', c('Hello, world', 'Hi bar')) # greeting target # [1,] "Hello" "world" # [2,] "Hi" "bar"