Elegant way for pattern matches with List-entrys Groovy -
whats common way of solving situation have text
this awesome text , nothing else matters
and have list
[ "nothing","bread","butter","fool" ]
and want check if of words in string inside list
my soulution far :
boolean check = false string mystring = "this awesome text , nothing else matters" list mylist = [ "nothing","bread","butter","fool" ] def stringlist = mystring.tokenize(" ") stringlist.each{ if( in mylist ){ check = true } }
is there more performant or better elegant way handle ?
how handle punctuation marks ?
for suggestions in advance
i @ using of collection methods. intersect comes mind.
def mystring = "this string example" def words = ['my', 'list', 'of', 'stuff'] def matches = mystring.tokenize(" ").intersect(words) println matches def check = (matches.size() > 0)
Comments
Post a Comment