Skip to contents

Attach a standardized error message to a regex argument. By default, the message will be "must match the regex pattern {regex}". If the input regex has a negate attribute set to TRUE, the message will instead be "must not match...". This message can be used with stabilize_chr() and stabilize_chr_scalar().

Usage

regex_must_match(regex)

Arguments

regex

(character) The regular expression pattern.

Value

The regex value with names() equal to the generated error message.

Examples

regex_must_match("[aeiou]")
#> must match the regex pattern {.val [aeiou]} 
#>                                   "[aeiou]" 

# With negation:
regex <- "[aeiou]"
attr(regex, "negate") <- TRUE
regex_must_match(regex)
#> must not match the regex pattern {.val [aeiou]} 
#>                                       "[aeiou]" 
#> attr(,"negate")
#> [1] TRUE