regulaR

Regular expressions for humans, a port of Ruby's Regularity library to R (see https://github.com/kevinushey/rex for current development)

#RegulaR
Regular expressions for humans, a port of Ruby’s Regularity library

Build Status

Development of this library is moving to rex, which provides a more robust R friendly framework

regulaR is a human friendly regular expression builder for R. While regular
expressions are a powerful way to match text, they are sometimes difficult to
document and understand when written. R also has escaping issues with regular
expression this library hopes to solve.

So instead of writing

regex = "^[0-9]{3}-[A-Za-z]{2}#?(?:a|b)c{2,4}\\$$"

You can write


regex = regulaR() %>% start_with(3, digits) %>%
  then('-') %>%
  then(2L, letters) %>%
  maybe('#') %>%
  one_of(c('a','b')) %>%
  between(c(2L,4L), 'c') %>%
  end_with('$')

See Also

  • rex for an alternate (better?) implementation

This package is inspired by @hadley’s tweet