Match regular expression
Returns the positions of substrings that match the regular expression.
regexp(s, pat, ignorecase = FALSE, once = FALSE, split = FALSE) regexpi(s, pat, once = FALSE, split = FALSE)
s |
Character string, i.e. of length 1. |
pat |
Matching pattern as character string. |
ignorecase |
Logical: whether case should be ignored;
default: |
once |
Logical: whether the first are all occurrences should be found; default: all. |
split |
Logical: should the string be splitted at the occurrences of the pattern?; default: no. |
Returns the start and end positions and the exact value of substrings
that match the regular expression. If split
is choosen, the
splitted strings will also be returned.
A list with components start
and end
as numeric vectors
indicating the start and end positions of the matches.
match
contains each exact match, and split
contains the
character vector of splitted strings.
If no match is found all components will be NULL
, except
split
that will contain the whole string if split = TRUE
.
This is the behavior of the corresponding Matlab function, though the
signature, options and return values do not match exactly.
Notice the transposed parameters s
and pat
compared to the
corresponding R function regexpr
.
s <- "bat cat can car COAT court cut ct CAT-scan" pat <- 'c[aeiou]+t' regexp(s, pat) regexpi(s, pat)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.