You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My code removes some text from the end of some other text using sub().
fixed_regex_linter() (incorrectly) suggests that my regular expression is static (example 1 below) if I use the symbol "\>" to match the empty string at end of a word. The suggestion with fixed = TRUE does not reproduce my desired outcome. However, fixed_regex_linter() correctly recognizes that regular expressions with "$" and "\b" are not static (examples 2 and 3) - obviously, I could use one of those instead.
I am not sure whether this has anything to do with the fact that regular expressions with "$" and "\b" work for both perl = FALSE and perl = TRUE while those with "\>" work only for perl = FALSE (?regex).
Example: trim "_stuff" only from end of "name_stuff_more_stuff" with desired result "name_stuff_more"
# 1) Approach "\>"
print(sub("_stuff\\>", "", "name_stuff_more_stuff"))
#> [1] "name_stuff_more"# Lintlintr::lint(
text='sub("_stuff\\\\>", "", "name_stuff_more_stuff")',
linters=lintr::fixed_regex_linter()
)
#> <text>:1:5: warning: [fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use "_stuff>" with fixed = TRUE.#> sub("_stuff\\>", "", "name_stuff_more_stuff")#> ^~~~~~~~~~~# Suggestion by `fixed_regex_linter()` is incorrect
print(sub("_stuff>", "", "name_stuff_more_stuff", fixed=TRUE))
#> [1] "name_stuff_more_stuff"
I think at root we want to detect the value of perl= and tweak the logic for what's a fixed regex or not accordingly. There are very subtle (and rare! \< is almost unheard of 😸) differences.
Hi @janlimbeck, we're all volunteers to if this affects you a lot, feel free to take it up & go for a fix! PRs welcome; happy to help you along if you're stuck.
My code removes some text from the end of some other text using
sub()
.fixed_regex_linter()
(incorrectly) suggests that my regular expression is static (example 1 below) if I use the symbol "\>" to match the empty string at end of a word. The suggestion withfixed = TRUE
does not reproduce my desired outcome. However,fixed_regex_linter()
correctly recognizes that regular expressions with "$" and "\b" are not static (examples 2 and 3) - obviously, I could use one of those instead.I am not sure whether this has anything to do with the fact that regular expressions with "$" and "\b" work for both
perl = FALSE
andperl = TRUE
while those with "\>" work only forperl = FALSE
(?regex).Example: trim "_stuff" only from end of "name_stuff_more_stuff" with desired result "name_stuff_more"
Created on 2022-07-27 by the reprex package (v2.0.1)
Created on 2022-07-27 by the reprex package (v2.0.1)
Created on 2022-07-27 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered: