Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert rex-style regexes to normal/conventional form regexes #56

Open
debajyoti7 opened this issue Jun 15, 2017 · 3 comments
Open

Convert rex-style regexes to normal/conventional form regexes #56

debajyoti7 opened this issue Jun 15, 2017 · 3 comments

Comments

@debajyoti7
Copy link

For eg.
Convert rex-style [[:alpha:]](?:(?:[[:digit:]]){1,2}(?:[[:alpha:]]){1,2})(?:(?:[[:digit:]]){6,7})
to conventional style [A-Za-z](?:(?:[\d]){1,2}(?:[A-Za-z]){1,2})(?:(?:[\d]){6,7})
so they can be plugged into external (non-R) models directly.

@jimhester
Copy link
Member

The [:alpha:] is a POSIX character classes and are actually widely used outside of R. If your language does not support them there is a table in the above link that supplies conversions. You could convert the regular expressions by defining a map and a call to gsub().

convert <- function(x) {
  map <- c("\\[:alpha:\\]" = "a-zA-Z", "\\[:digit:\\]" = "0-9")
  for (i in seq_along(map)) {
    x <- gsub(names(map)[[i]], map[[i]], x)
  }
  x
}
convert("[[:alpha:]](?:(?:[[:digit:]]){1,2}(?:[[:alpha:]]){1,2})(?:(?:[[:digit:]]){6,7})")
#> [1] "[a-zA-Z](?:(?:[0-9]){1,2}(?:[a-zA-Z]){1,2})(?:(?:[0-9]){6,7})"

@debajyoti7
Copy link
Author

@jimhester Thank you.
That's actually how I'm handling it right now and supplying the outputs to Watson Knowledge Studio. The easy check for me is to make it compliant to this web platform.
I opened the issue as suggested by @kevinushey via Twitter.

@kevinushey
Copy link
Collaborator

It might be worth considering allowing:

  1. Different 'modes' for rex to operate in, defining how it generates regular expressions,
  2. Some kind of user hook that defines what replacement is used for a particular rex construct.

... although this is unlikely to happen in the short-term.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants