Skip to contents

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.

Usage

re_match(pattern, 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_compile

IGNORECASE

Flag to indicate case-insensitive matching.

I

Abbreviation for IGNORECASE.

MULTILINE

Flag to indicate multi-line matching, where ^ and $ match the start and end of each line.

M

Abbreviation for MULTILINE.

DOTALL

Flag to indicate that . (dot) should match any character including newline.

S

Abbreviation for DOTALL

VERBOSE

Flag to allow a more verbose regex syntax, which can include comments and whitespace for readability.

X

Abbreviation for VERBOSE

NOFLAG

Flag 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
#>