testing: Is Expression Valid and Does It Extract/Remove/Split as...

Description Usage Arguments Details Value See Also Examples

Description

A logical test of a regular expression's validity, extraction, removal, splitting results. These functions are useful for unit testing of regular expressions.

Usage

1
2
3
4
5
6
7
test_extract(regex, input, output, stringi = FALSE)

test_remove(regex, input, output, stringi = FALSE)

test_split(regex, input, output, stringi = FALSE)

test_valid(regex, stringi = FALSE)

Arguments

regex

A regular expression to test.

input

The intput string(s) to extract/remove/split from.

output

The desired output of:

extract

regmatches(input, gregexpr(regex, input, perl = TRUE))

remove

gsub(regex, "", input, perl = TRUE)

split

strsplit(input, regex, perl = TRUE)

lofical.

If TRUE stringi's implementation of reguar expressions is utilized for testing. This allows for more flexible use of regular expressions.

Details

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.

Value

Returns the results of all.equal for the input and desired output.

See Also

all.equal, gsub, gregexpr, regmatches, test

Examples

1
2
3
4
5
6
7
8
test_extract("\\w+", "I like candy.", list(c("I", "like", "candy")))

test_remove("^\\s+|\\s+$", " I like candy ", "I like candy")

test_split("(?<=[.?!])\\s+", "I see! When? Oh that's good.",
    list(c("I see!", "When?", "Oh that's good.")))

test_valid("\\w+")

trinker/regextools documentation built on May 31, 2019, 9:51 p.m.