regular expressions – Multiple regexp replace in string

I need to search for every declared variable in a string with format %^{var}, prompt a value and replace in place.

(let ((primitive "(%^{size}, %^{center})"))
  (if (string-match "%^{\\([^}]*\\)}" primitive)
      (replace-regexp-in-string (format "%%^{%s}" (match-string 1 primitive))
                                (read-string (format "%s: " (match-string 1 primitive)))
  (message "%s" primitive))

However this does not replace the variable in the string and the primitive is printed unchanged.

(Later when I fix this problem, I’m changing if to while so it does it for every variable in the string)

Read more here: Source link