Skip to contents

re_compile compiles a regular expression pattern with specified flags. This function allows setting various flags akin to regex modifiers in other programming languages like Python. The flags control various aspects of pattern matching. This function is really just a way to set flag arguments with a constant variable.

Usage

re_compile(pattern, IGNORECASE, I, MULTILINE, M, DOTALL, S, VERBOSE, X, NOFLAG)

Arguments

pattern

The regular expression pattern to be compiled.

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

An object of class "Pattern" representing the compiled regular expression with the specified flags.

Examples

pattern <- re_compile("^abc", IGNORECASE)
pattern <- re_compile("end$", M = TRUE)
pattern <- re_compile("a.b", DOTALL = TRUE)