Skip to contents

re_search searches for occurrences of a specified pattern (regular expression) 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_search(pattern, string, ...)

Arguments

pattern

A regular expression pattern or a compiled pattern object.

string

A character vector where each element is a string in which to search for 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 list where each element is a character vector containing all matches found in the corresponding element of string. If no matches are found, the element will be character(0).

Examples

pattern <- re_compile("\\d+")
re_search(pattern, "abc 123 xyz") # Finds "123"
#> [[1]]
#> [1] "123"
#> 
re_search("\\bword\\b", "A sentence with the word.") # Finds "word"
#> [[1]]
#> [1] "word"
#>