[英]Groovy FindAll Roughly/Like
I am trying to do something in Groovy similar to SQL's WHERE NAME LIKE %JOHN%
我试图在Groovy中做一些类似于SQL的
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. 如果我使用==,这是有效的,但我的代码执行LIKE搜索有问题。
我想你需要:
json.entries.findAll { it.name.toUpperCase() ==~ /.*${lookupQuery.toUpperCase()}.*/ }
The problem is that lookupQuery
isn't inserted in the regular expression. 问题是
lookupQuery
没有插入正则表达式中。 In this case however, you don't really need to use regular expressions: 但是,在这种情况下,您实际上不需要使用正则表达式:
json.entries.findAll { it.name.toUpperCase().contains(lookupQuery.toString().toUpperCase()) }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.