-
Notifications
You must be signed in to change notification settings - Fork 196
Closed
Description
Hi, and thank you for your work on stringr!
I’d like to suggest a new function: str_replace_n(), which would allow replacing the nth match of a pattern.
This would cover common but currently awkward use cases, such as replacing only the last match or the second match.
Expected output:
str_replace_n("a-b-c-d", "-", "+", n = 1) #with n=1, we get the same as str_replace()
#> "a+b-c-d"
str_replace_n("a-b-c-d", "-", "+", n = 2)
#> "a-b+c-d"
str_replace_n("a-b-c-d", "-", "+", n = -1)
#> "a-b-c+d"Would this kind of feature be aligned with the design goals of the package?
If not, would you consider at least re-exporting stringi::stri_replace_last()?
Thanks again for considering it!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels