I’m looking for a Java class that for a given string “the ${animal} jumped over the ${target}.” is able to pull out the variable names, ie ‘animal’ and ‘target’.
I had hoped StrSubstitutor in Commons Lang had a method
getVariables(String str) : List<String>
… but no such luck.
Yes I could write this myself, but I’m certain there must be a 3rd party library that exists out there that does this.
You could just do a simple regex match if you really just want to pull out those values and avoid the dependency of an entire library:
Storing the pattern as a member variable will improve performance.