String replace with regex
String replace with regex patternλ︎
clojure.string/replace
takes a string, a pattern and a substring that will replace matching patterns.
Groups can be referred to in the substring replacement
Replace with the value of a function applied to the match:
(clojure.string/replace "mississippi" #"(.)i(.)"
(fn [[_ b a]]
(str (clojure.string/upper-case b)
"--"
(clojure.string/upper-case a))))
"M--SS--SS--Ppi"
clojure.string/replace-first
is a variation where just the first occurrence is replaced.