
Originally Posted by
andyrh3
This works fine but I was hoping to use a more elegant solution. Can anyone help with the following points:
1. Can I improve the elvis operator? I tried the below instead of the above but it did not work. I thought that it would implicitly apply the params.q to my qStr variable if the condition was true?
def qStr = params.q != "" ?: "*"
This is the typical code you would use:
Code:
def qStr = params.q ?: "*"
If params.q is a non-empty string (and hence also not null), then it's value will be used. Otherwise the "*" string will be assigned to qStr instead.

Originally Posted by
andyrh3
2. How can I perform a regExpression and check for all non-expected entries. I.e. If I enter a space into the field this also causes an error.
I'm not quite sure what you're after, but you can do something like:
Code:
if (qStr =~ /\S+/) {
// Everything is OK
}
If you want more information than that you will have to be more explicit as to what you're trying to do. Are you after a particular regular expression for example?