Very stuck on a problem which I thought would be pretty simple. As an example I have the following strings I need to interpolate values into:
” some other text or nothing ${who} is ${what} some other text or nothing”
” some other text or nothing something${postfix} some other text or nothing”
“some other text or nothing ${prefix}something some other text or nothing”
What I need is to group the ${…} things so that I can replace them with a value later.
I’m executing my RegEx matches in Clojure, so really in behind the scenes it’s using the Java RegEx libraries. So far I’ve tried:
user=> (def regex #"(\$\{\w+\})*")
#'user/regex
user=> (def matcher (re-matcher regex "${who} is a great ${that}person"))
#'user/matcher
user=> (re-find matcher)
["${who}" "${who}"]
user=> (re-find matcher)
["" nil]
I can’t seem to get ${that} to be considered a match…
The expression
should work, altho you may want to use this instead:
Your expression has a
*at the end which will break it in some cases, altho it should work in this case (if you don’t need to double escape anything). Are you using the regex API correctly? Does it work with simple matches like\w+?