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

Enabling PCRE RegEx patterns #262

Open
Michiel91 opened this issue May 6, 2024 · 0 comments
Open

Enabling PCRE RegEx patterns #262

Michiel91 opened this issue May 6, 2024 · 0 comments

Comments

@Michiel91
Copy link

Michiel91 commented May 6, 2024

I often use checkmate to verify character vectors based on certain criteria, combined with a RegEx pattern match. One limitation frequently popping up in the current version is that not all RegEx patterns are supported, for example lookbehind expressions. This is due to checkmate running grepl without perl = TRUE in checkCharacterPattern. With perl = FALSE the patterns are handled by the TRE engine, while handled by the PCRE engine for perl = TRUE.

It would be great if users could indicate whether or not to use "perl" (or TRE vs PCRE) in all checkmate functions with a pattern argument. A passthrough of this argument to the underlying grepl code would then enable the usage of much more (and often more advanced) RegEx patterns.

Below is an example to reproduce the behavior of checkmate and grepl I am referring to:

# Define example values and RegEx
example_values <- c("value1", "some_string", "Empty", "482733")
example_regex <- "^(?!Empty$).+$"

# Check with checkmate: fails due to "Invalid regexp"
checkmate::test_character(x = example_values, pattern = example_regex)

# Check with grepl perl = FALSE: fails due to "Invalid regexp"
base::grepl(x = example_values, pattern = example_regex)

# Check with grepl perl = TRUE: works!
base::grepl(x = example_values, pattern = example_regex, perl = TRUE)

Many thanks in advance for taking this proposal into consideration! Let me know if I can help by providing additional input.

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

1 participant