tags:

views:

59

answers:

3

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.

+1  A: 
s/\${(.*?)}/:$1/g;

Will answer the question as stated.

Whether it solves your problem or not, I am unsure.

Anon.
+1  A: 

Using generic regex syntax since you didn't specify a language:

/\$\{([^}]+)}/:\1/g
/\$\{(.+?)}/:\1/g  # same thing in this case
Roger Pate
:) 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
+1  A: 

Don't know what environment you're in, but the pattern should be $\{([^}])+\} and you should replace it with :$1

David Hedlund