0

I have a domain-class called option. There is an attribute called name.

The names are like:

abc.1
abc.2
xxx.1
xxx.2
xxx.3

I want all options that start with abc. Normally I use Options.findByName("xyz") But i want all that start with abc. So in that example:

abc.1
abc.2

The regex could be /abc(.).*/

But where I have to write that?

tim_yates
  • 167,322
  • 27
  • 342
  • 338
user2244536
  • 67
  • 2
  • 10

2 Answers2

2

If you need only simple "startsWith" condition, you can use like:

  Options.findAllByNameLike("abc%")
lukelazarovic
  • 1,510
  • 11
  • 19
0

Consider using colusers inside the findAll /findByName method Have u tried this one ?

Example

def result = ["abc1", "acb2", "abc3"].findAll { it ==~ /abc.*/ }

or in your case

def result = Options.findByName { it ==~ /abc.*/ }

Or refer this link for bunch of reference on regular expression http://groovy.codehaus.org/Regular+Expressions

Cheers!

Develop4Life
  • 7,581
  • 8
  • 58
  • 76