re_match checks whether each element of a character vector matches a specified pattern (regular
expression) at the start. If the provided pattern is not already a compiled pattern object, it compiles it using
re_compile. The function ensures that the matching occurs at the beginning of the string.
Arguments
- pattern
A regular expression pattern or a compiled pattern object.
- string
A character vector where each element is a string to be matched against the pattern at the beginning.
- ...
Arguments passed on to
re_compileIGNORECASEFlag to indicate case-insensitive matching.
IAbbreviation for IGNORECASE.
MULTILINEFlag to indicate multi-line matching, where
^and$match the start and end of each line.MAbbreviation for MULTILINE.
DOTALLFlag to indicate that
.(dot) should match any character including newline.SAbbreviation for DOTALL
VERBOSEFlag to allow a more verbose regex syntax, which can include comments and whitespace for readability.
XAbbreviation for VERBOSE
NOFLAGFlag to indicate that no flags should be set.
Value
A list where each element is a character vector containing the match found at the start of the corresponding
element of string, or character(0) if there is no match at the start.
Examples
pattern <- re_compile("\\d{3}")
re_match(pattern, "123abc")
#> [[1]]
#> [1] "123"
#>
re_match("abc", "xyzabc")
#> [[1]]
#> [1] NA
#>