pracma (version 1.9.9)

regexp: 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: FALSE.
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.

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.

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.

See Also

regexpr

Examples

s <- "bat cat can car COAT court cut ct CAT-scan"
pat <-  'c[aeiou]+t'
regexp(s, pat)
regexpi(s, pat)