我试图在Groovy中做一些类似于SQL的WHERE NAME LIKE %JOHN%
这是我有的:
response.entries = json.entries.findAll { it.name.toUpperCase() =~ /lookupQuery.toString().toUpperCase()/ }
如果我使用==,这是有效的,但我的代码执行LIKE搜索有问题。
问题是lookupQuery
没有插入正则表达式中。但是,在这种情况下,您实际上不需要使用正则表达式:
json.entries.findAll { it.name.toUpperCase().contains(lookupQuery.toString().toUpperCase()) }
我想你需要:
json.entries.findAll { it.name.toUpperCase() ==~ /.*${lookupQuery.toUpperCase()}.*/ }