This package wraps the rexpy python module, part of the TDDA module, which generates automatic constraints on data sets given examples. More info can be found on the TDDA blog.
This is an extremely alpha package wrapping some pretty beta code, so use with caution! It does not currently work on Windows.
You can install rexr from github with:
# install.packages("devtools")
devtools::install_github("noamross/rexr")
Since rexr calls python code via the SnakeCharmR package, you need Python >= 2.7 and a build environment to install it.
rex_extract()
generates regular expressions that match a character vector. The RexPy library attempts to create a minimal set of regexes that narrowly capture all the values.
library(rexr)
rex_extract(c("EH1", "7JQ", "WC1", "4AA", "G2", "3PQ"))
#> [1] "^[A-Za-z0-9]{2,3}$"
rex_extract(c("123-AA-971", "12-DQ-802", "198-AA-045", "1-BA-834"))
#> [1] "^\\d{1,3}\\-[A-Z]{2}\\-\\d{3}$"