Most stringr
functions are just wrappers around corresponding stringi
functions. str_replace_all
is one of those. Yet my code does not work with stri_replace_all
, the corresponding stringi
function.
I am writing a quick regex to convert (a subset of) camel case to spaced words.
I am quite puzzled as to why this works:
str <- "thisIsCamelCase aintIt"
stringr::str_replace_all(str,
pattern="(?<=[a-z])([A-Z])",
replacement=" \\1")
# "this Is Camel Case ain't It"
And this does not:
stri_replace_all(str,
regex="(?<=[a-z])([A-Z])",
replacement=" \\1")
# "this 1s 1amel 1ase ain't 1t"
stri_replace_all(str, regex = "(?<=[a-z])(?=[A-Z])", replacement=" ")
– Wulf