Re: [Rd] FR: valid_regex() to test string validity as a regular expression

2023-10-11 Thread Michael Chirico via R-devel
Great to know this exists in package space! Of course, using re2 validation for a regex to be executed with TRE (via grep*) is just begging for trouble (e.g. [1] suggests re2 is closer to PCRE, [2] says "mostly" PCRE compatible). And overhauling everything to use re2 just for regex validation is h

Re: [Rd] FR: valid_regex() to test string validity as a regular expression

2023-10-11 Thread Toby Hocking
Hi Michael, it sounds like you don't want to use a CRAN package for this, but you may try re2, see below. > grepl("(invalid","subject",perl=TRUE) Error in grepl("(invalid", "subject", perl = TRUE) : invalid regular expression '(invalid' In addition: Warning message: In grepl("(invalid", "subject

Re: [Rd] FR: valid_regex() to test string validity as a regular expression

2023-10-10 Thread Michael Chirico via R-devel
> Grepping an empty string might work in many cases... That's precisely why a base R offering is important, as a surer way of validating in all cases. To be clear I am trying to directly access the results of tre_regcomp(). > it is probably more portable to simply be prepared to propagate such er

Re: [Rd] FR: valid_regex() to test string validity as a regular expression

2023-10-09 Thread Tomas Kalibera
On 10/10/23 01:57, Michael Chirico via R-devel wrote: > It will be useful to package authors trying to validate input which is > supposed to be a valid regular expression. > > As near as I can tell, the only way we can do so now is to run any > regex function and check for the warning and/or cond

Re: [Rd] FR: valid_regex() to test string validity as a regular expression

2023-10-09 Thread Duncan Murdoch
On 09/10/2023 7:57 p.m., Michael Chirico via R-devel wrote: It will be useful to package authors trying to validate input which is supposed to be a valid regular expression. As near as I can tell, the only way we can do so now is to run any regex function and check for the warning and/or conditi

[Rd] FR: valid_regex() to test string validity as a regular expression

2023-10-09 Thread Michael Chirico via R-devel
It will be useful to package authors trying to validate input which is supposed to be a valid regular expression. As near as I can tell, the only way we can do so now is to run any regex function and check for the warning and/or condition to bubble up: valid_regex <- function(str) { stopifnot(i