vec_to_regex: Collapse vectors into a regex pattern

View source: R/string_tools.R

vec_to_regexR Documentation

Collapse vectors into a regex pattern

Description

Collapse vectors into a regex pattern

Usage

vec_to_regex(..., sep = "|", wrap = c("(", ")"))

Arguments

...

(Vector) Vectors that will be coerced into character. Duplicated elements from the vectors are removed.

sep

(Char) Separator to use between elements of ...

wrap

(Char) 2-element vector of text to wrap the pattern with. wrap[1] is placed on the left side of the pattern, wrap[2] is placed on the right side.

Value

A character string where every element of ... is collapsed with sep, and wrapped with wrap.

Authors

Examples

vec_to_regex(month.abb)
#> [1] "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"

vec_to_regex(letters[1:6], sep = "", wrap = c("([", "]+)"))
#> [1] "([abcdef]+)"


DesiQuintans/desiderata documentation built on April 9, 2023, 5:43 a.m.