如何使用regexp与Drools中的字符串匹配参数?

时间:2012-12-13 06:36:35

标签: java regex drools rules

我想在drools的when部分使用in build关键字匹配字符串。

e.g。

rule "test"
when Foo( fooid : id )
     Bar( barid : id, barid not matches "ID=" + fooid + ", " + name )
then ...

它似乎没有用,因为它抱怨“ID =”+ fooid +“,”+名称。

但如果我删除所有参数,它就会运行,即只留下“ID =”

所以问题似乎在于如何在匹配模式中包含更多参数,您将如何解决这个问题?

谢谢

2 个答案:

答案 0 :(得分:2)

在检查规则之前,你可以保存fooid,barid。不确定是否可能,你可以尝试一下。

string fooid = Food id // use correct syntax
string barid = Bar id // use correct syntax
string checkstring = "ID=" + fooid + "," + name

rule "test"  
    when   
        barid: String(this not matches "(?i)." + checkstring)  
    then  
        System.out.println(checkstring);  
    end  

备注:

(?i) - 忽略大小写

答案 1 :(得分:0)

规则" PuneUser_Rule"

no-loop true
ruleflow-group "EvalLoopcondition"
when
    m:HelloProcessModel(userlocation in ("PuneUser"), count < 4)
then
    m.setLoopcondition(6);update(m);

在这里我们检查规则,如果PuneUser和count小于4,那么循环将从count到loopcondition运行,直到6。

只有当您检查字符串是否为PuneUser

时,才会遵循此规则