I am trying to write a Julia function that performs a find and replace operation on each element in an array of strings using regular expressions. It is essentially a wrapper around a broadcasted replace() call. If you are familiar with R's stringr package, this function should more or less work the same as stringr::str_replace_all().
The code below replaces all instances of 'ee' with 'EE', replacing "greetings" with "grEEtings":
arr = ["hi", "hello", "welcome", "greetings"]
replace.(arr, r"e{2}" => "EE")
The function I wrote does not return modifications of the values in arr:
function str_replace_all(string::String, pattern::String, replacement::String)
replace.(string, Regex(pattern) => replacement)
end
str_replace_all(arr, "e{2}", "EE")
What went wrong? Thanks!