Does anyone know if there is a way to make for loops in drools ?.
I'm trying to iterate over a list of strings to see if one of the strings matches a pattern, for example.
def listOfStrings = ['a','a.b','abc'] for(String s:listOfStrings){ if(s matches "^ab*$"){ return true } }
I wrote the following rule based on documentation that I could find, but I don't think the syntax is correct.
rule "Matcher" when TestClass : TestClass(($s matches "^ab*$") from listOfStrings, count($s)) then TestClass.setResponse( "Condition is True !!" ); end
I find it difficult to find good documentation in drl
I would appreciate any help anyone can give.
Based on the previous answer, I tried the following
rule "Matcher" when TestClass:TestClass(String( this matches "^ab*$" ) from listOfStrings) then TestClass.setResponse( "Condition is True !!" ); end
However, now I get the following error message:
[43,197]: unknown:43:197 Unexpected token 'this'
drools
Mth
source share