test_extract(regex, input, output)test_remove(regex, input, output)test_split(regex, input, output)test_valid(regex)
regmatches(input, gregexpr(regex, input, perl = TRUE))
gsub(regex, "", input, perl = TRUE)
strsplit(input, regex, perl = TRUE)
Returns the results of all.equal
for the
input
and desired output
.
A logical test of a regular expression's validity, extraction, removal, splitting results. These functions are useful for unit testing of regular expressions.
These functions are inspired by Hadely Wickham's testthat
package. They can be used with testthat to test that regular
expressions are valid, extracting, removing, and splitting as expected. The
user may create their own tests and utilize all.equal
or
expect_equal
to ensure the expression is acting as
desired.
test_extract("\\w+", "I like candy.", list(c("I", "like", "candy")))[1] TRUEtest_remove("^\\s+|\\s+$", " I like candy ", "I like candy")[1] TRUEtest_split("(?<=[.?!])\\s+", "I see! When? Oh that's good.", list(c("I see!", "When?", "Oh that's good.")))[1] TRUEtest_valid("\\w+")[1] TRUE