Package for constructing regular expressions via functions

My google is failing me. I believe I've seen a package in R that allows you to construct a regular expression step by step. Something like

r = startswith("a") %>% endswith("b") # "^a.*b$"

Can someone remind me the name of the package?

Hi @pdeffebach, could you say a little more about your context, and what you'd like to be able to do? I know of helper functions like those, but they don't produce regular expressions.

Maybe the ore package

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

I just want to use regex to determine if a string matches a pattern, but you know the saying "you decide to do regex, now you have two problems". A MWE would be

street _names = c("myrtle street", "poplar st", "oak road", "maple rd")
find_streets  = function(street_name) {
    str_detect(street, "st$") | str_detect(street, "street")
}

I remember hearing about a package that allows users to construct something like a regular expression, without worrying about writing a regex itself.

One aid is regexplain which has the added benefit of being an RStudio plugin. Another possibility is devtools::install_github("VerbalExpressions/RVerbalExpressions")

I haven't used any of these, and didn't see anything else. There may be constructors that you could use in other languages and paste the resulting expressions as a stringr regex pattern that fit in a piped workflow

1 Like

So maybe something like http://buildregex.com/, but in R?

In RStudio, str_view() and str_view_all() can be useful for experimenting with regular expressions; I learned about them in section 14.3 of 'R for Data Science'.

1 Like

Cool! I think I'll be trying that out soon.

1 Like