validate(pattern, single = TRUE, trim = FALSE, clean = FALSE, dictionary = getOption("regex.library"))
fixed = TRUE
) to be matched in the given
character vector.TRUE
only returns true if the output string
is of length one. If FALSE
multiple strings and multiple outputs are
accepted.TRUE
removes leading and trailing white
spaces.TRUE
extra white spaces and escaped
character will be removed.pattern
begins with "@rm_"
.rm_XXX
functions but with user defined defaults.
Generate function to validate regular expressions.
validate
uses qdapRegex's built in regular
expressions. As this patterns are used for text analysis they tend to be
flexible and thus liberal. The user may wish to define more conservative
validation regular expressions and supply to pattern
.
## Single element email valid_email <- validate("@rm_email") valid_email(c("tyler.rinker@gmail.com", "@trinker"))[1] FALSE## Multiple elements valid_email_1 <- validate("@rm_email", single=FALSE) valid_email_1(c("tyler.rinker@gmail.com", "@trinker"))[1] TRUE FALSE## single element address valid_address <- validate("@rm_city_state_zip") valid_address("Buffalo, NY 14217")[1] TRUEvalid_address("buffalo,NY14217")[1] TRUEvalid_address("buffalo NY 14217")[1] FALSEvalid_address2 <- validate(paste0("(\\b([A-Z][\\w-]*)+),", "\\s([A-Z]{2})\\s(?<!\\d)\\d{5}(?:[ -]\\d{4})?\\b")) valid_address2("Buffalo, NY 14217")[1] TRUEvalid_address2("buffalo, NY 14217")[1] FALSEvalid_address2("buffalo,NY14217")[1] FALSEvalid_address2("buffalo NY 14217")[1] FALSE