I would like to replace all demo words in "demo demo demo demo demo1 Demo" by using the following codes, but the result seems a little bit weird.
(string/replace
"demo demo demo demo demo1 Demo"
(re-pattern (str "(?i)" "(^|\\s)(" "demo" ")($|\\s)"))
"$1[[$2]]$3")
;; => "[[demo]] demo [[demo]] demo demo1 [[Demo]]"
Why are the second and fourth ones not been replaced? Appreciated any explanation and solutions.
edit: did some experiments. If another space is added before the second word, then it can be successfully replaced, so it looks like the word boundary cannot be used twice. I can do the replacement twice to replace all those demo words, but it is cumbersome. Is there any better solutions?
(string/replace
"demo demo demo demo demo1 Demo"
(re-pattern (str "(?i)" "(^|\\s)(" "demo" ")($|\\s)"))
"$1[[$2]]$3")
;; => "[[demo]] [[demo]] demo [[demo]] demo1 [[Demo]]"