Skip to contents

re_contains checks whether a specified pattern (regular expression) is found within each element of a character vector. If the provided pattern is not already a compiled pattern object, it compiles it using re_compile.

Usage

re_contains(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 checked against the pattern.

...

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 logical vector of the same length as string, indicating whether each element contains a match for the pattern.

Examples

pattern <- re_compile("^abc", IGNORECASE)
re_contains(pattern, "Abcdef")
#> [1] TRUE
re_contains("xyz$", "hello world xyz")
#> [1] TRUE