If I want to replace all occurrences of “apple” by “orange” in a file, I can use the Unix shell command
sed -i 's/apple/orange/g' filename.txt
What would be an equivalent Julia code?
If I want to replace all occurrences of “apple” by “orange” in a file, I can use the Unix shell command
sed -i 's/apple/orange/g' filename.txt
What would be an equivalent Julia code?
Start with Strings · The Julia Language
maybe create a regex literal r"<regex>"
, like this:
julia> occursin(r"(?i)apple|orange", "Orange or Apple")
true
julia> replace("Orange or Apple", r"(?i)apple" => "Orange")
"Orange or Orange"
Or even fancier:
julia> replace("Orange or Apple", r"(?i)apple" => titlecase("orange"))
"Orange or Orange"