I am currently working in an application where I need to find all occurrences of strings like ${[0-9-a-zA-Z]} in a bigger string. Here is my method:
def countVariables(str) {
def pattern = ~'${sss}'
def matcher = str =~ pattern
print matcher.count
}
Now the problem.
When I pass a string like “asidb ${sss} asodniasndin”, I get:
groovy.lang.MissingPropertyException: No such property: sss for class: ConsoleScript83
I think that, given that in Groovy ${} are properties, I’m having these conflicts.
In this case, I would have to run the whole text searching for the dollar sign and replacing it for something else? Or is there a simpler way to do this?
Regards!
Are you using single quotes so groovy doesn’t do the expansion and just gives you a string?
Ie: