Create a regex from components.

Share:

Description

Creates a regex from regex components.

Usage

1
create_regex(..., l = list(), sep = "[- ]?")

Arguments

...

Character vectors of regex components.

l

A list of character vectors for alternate specification.

sep

Regex for separating components of complete regex. Defaults to "an optional space or hyphen".

Value

A string containing a regex. Each element in the vectors are pasted together, separated by the sep value. Those character vectors are then preceded by "^" (regex for 'start of string'() and followed by "$" (regex for end of string). Finally, the regexes are collapsed with "|" (regex for 'or').

Examples

1
2
3
4
5
6
7
## Not run: 
cas_number_components <- c(
  "[[:digit:]]{1,7}", "[[:digit:]]{2}", "[[:digit:]]"
)
cas_number_rx <- create_regex(rx_components, sep = "-")

## End(Not run)