trinker / qdapRegex

qdapRegex is a collection of regular expression tools associated with the qdap package that may be useful outside of the context of discourse analysis.
50 stars 4 forks source link

Invalid patterns evaluated as valid by is.regex() #31

Open pieterjanvc opened 4 years ago

pieterjanvc commented 4 years ago

Hi,

Let me start by saying I really like your package! Very useful :)

However, I found several patterns that throw an error in R (using stringr::str_detect()) although they are evaluated as valid RegEx by your is.regex() function. They are all related to the curly brace {. These patterns might be correct for other software, but in R they fail in all stringr functions and most of the base grep cases

Patterns that throw error:

Grtz, PJ

trinker commented 2 years ago

Hi thanks for the report. This is because is.regex relies on base R for checking the regex (pretty low level checking):

is.regex <- function(pattern) {

    out <- suppressWarnings(try(gsub(pattern, "", "hello", perl=TRUE), silent = TRUE))
    ifelse(inherits(out, "try-error"), FALSE, TRUE)

}

Would you be willing to subit a pull request rewriting is.regex with stringi functions for the checking?