5

I can use the perl argument in gsub to change the case of individual subexpressions. For example if I want to find a lower case i followed by and apostrophe or end of string (redundant here) I could do:

gsub("(\\bi(\\b|'))", "\\U\\1", "i am able to move do it as i'm going to.", perl = TRUE)

## [1] "I am able to move do it as I'm going to."

Notice I and I'm are caps but it is not.

How can I do the same thing (is it possible) using stringi given that base and stringi use different regex engines.

stri_replace_all_regex("i am able to move do it as i'm going to.", "(\\bi(\\b|'))", "\\U$1")

## [1] "1 am able to move do it as 1'm going to."
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519

0 Answers0