[rules-users] Regular Expressions : Collections : matches problem

Gary Napier gnapier at cis.strath.ac.uk
Tue Sep 16 08:44:23 EDT 2008


Hi folks,

I have searched the archives and can't quite find the right way to write 
this rule, if it's possible.


In a nutshell i have a Global Collection of regular expression patterns. 
I would like a rule to take a single string from a fact and try to match 
it to any of the saved patterns.

so i have a basic test harness here to try :

global  Collection    regexpString

rule "Test"
   when
       $TEST : TEST( NAME _*matches*_ regexpString )
   then
       System.out.println("working");
end

--------------
The Collections is set outside the engine and contains test inputs of 
[".* Smith.*",".*-Jones"], and so would match "Dave Smith" or "Rupert 
Perry-Jones"


Can you help me fix the above code in order to do that. I am new to 
drools and am struggling to get my head around complexities like 
accumulates and collect(). Would these help?
In the worst case can i create my own function that uses an iterator and 
java's own regular expression features to do this? (i'm guessing via an 
Eval)

Any help or creative criticism of the design would be appreciated,

Drools 4.07, java6,  (recovering JESS addict ;-) )

Thanks
Gary




More information about the rules-users mailing list