VerbalExpressions / RVerbalExpressions

:speech_balloon: Create regular expressions easily
https://rverbalexpressions.netlify.com/
Other
280 stars 12 forks source link

Creating a set #23

Closed kwstat closed 5 years ago

kwstat commented 5 years ago

Without using rx_range(), how can I get an rx like [A-Z0-9] ? I tried many ideas and failed. For example:

R> rx_uppercase()
[1] "[A-Z]"
R> rx_digit()
[1] "\\d"
R> rx_either_of(NULL, rx_uppercase(), rx_digit())
[1] "(\\[A-Z\\]|\\\\d)"

This doesn't work because each part is sanitized.

tylerlittlefield commented 5 years ago

At this moment, I believe rx_range is you're only option.

Nested rx_* we're an issue early on see #9, rx_group was one suggestion to your example. We had a lot of features at one point but (if I remember correctly) I removed some of them to bring it back to the VerbalExpressions structure (i.e. how all the other implementations work), still this repo does have extras.

tylerlittlefield commented 5 years ago

This is now possible using the old rx.string method, install the latest if you'd like to give it a try:

library(RVerbalExpressions)

rx() %>% 
  rx_either_of(
    rx_uppercase(), 
    rx_digit()
  )
#> [1] "([A-Z]|\\d)"

Or with rx_range:

rx() %>% 
  rx_range(c("A", "Z", 0, 9))
#> [1] "[A-Z0-9]"