The problem is that lookupQuery
isn't inserted in the regular expression.
In this case however, you don't really need to use regular expressions:
json.entries.findAll { it.name.toUpperCase().contains(lookupQuery.toString().toUpperCase()) }
Question
I am trying to do something in Groovy similar to SQL's WHERE NAME LIKE %JOHN%
Here is what I have:
response.entries = json.entries.findAll { it.name.toUpperCase() =~ /lookupQuery.toString().toUpperCase()/ }
This is working if I use ==, but something is wrong with my code doing a LIKE search.
Solution
The problem is that lookupQuery
isn't inserted in the regular expression.
In this case however, you don't really need to use regular expressions:
json.entries.findAll { it.name.toUpperCase().contains(lookupQuery.toString().toUpperCase()) }
OTHER TIPS
I think you need:
json.entries.findAll { it.name.toUpperCase() ==~ /.*${lookupQuery.toUpperCase()}.*/ }