re_match {re}R Documentation

Match a pattern at the start of a string

Description

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.

See Also

Python re.match() equivalent functionality documentation

Examples

pattern <- re_compile("\\d{3}")
re_match(pattern, "123abc")
re_match("abc", "xyzabc")

[Package re version 0.1.0 Index]