I am trying to build a regular expression to replace unresolved velocity variables with the syntax required by other parameterized variable frameworks such as spring jdbc and hibernate. Essentially, I want a replacement pattern to find and replace ${a} with :a, ${b} with :b, etc.
views:
59answers:
3
+1
A:
s/\${(.*?)}/:$1/g;
Will answer the question as stated.
Whether it solves your problem or not, I am unsure.
Anon.
2010-02-10 22:15:14
+1
A:
Using generic regex syntax since you didn't specify a language:
/\$\{([^}]+)}/:\1/g
/\$\{(.+?)}/:\1/g # same thing in this case
Roger Pate
2010-02-10 22:15:39
:) I was curious about the perl compatible regex, but actual language is java. Working Test case is:System.out.println("${a} and ${b}".replaceAll("\\$\\{([^}]+)}", ":$1"));
gbegley
2010-02-10 22:47:25
+1
A:
Don't know what environment you're in, but the pattern should be $\{([^}])+\}
and you should replace it with :$1
David Hedlund
2010-02-10 22:16:44