Skip to content

StringReplace

Applies one or more replacement rules to a string.

$ wo 'StringReplace["Hello world", "world" -> "moon"]'
Hello moon

$1… expand into the replacement before it is evaluated, so they reach string literals inside a compound right-hand side:

$ wo 'StringReplace["abc", RegularExpression["(b)"] :> "<" <> "$1" <> ">"]'
a<b>c