regexp {pracma} | R Documentation |
Match regular expression
Description
Returns the positions of substrings that match the regular expression.
Usage
regexp(s, pat, ignorecase = FALSE, once = FALSE, split = FALSE)
regexpi(s, pat, once = FALSE, split = FALSE)
Arguments
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. |
Details
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.
Value
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
.
Note
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
.
See Also
Examples
s <- "bat cat can car COAT court cut ct CAT-scan"
pat <- 'c[aeiou]+t'
regexp(s, pat)
regexpi(s, pat)