[rules-users] Problem implementing dynamic regular expression

Wolfgang Laun wolfgang.laun at gmail.com
Mon Jan 24 12:38:06 EST 2011


If some value is variable, it must be privided in a fact - otherwise
the Inference Engine does not register any changes.

Notice that you cannot use "matches" in an eval, where plain Java (or
mvel) must be used.

-W

2011/1/24 Bruno Freudensprung <bruno.freudensprung at temis.com>:
>
> Thanks Wolfgang! My sincere apologies for the wrong answer.
> Does it mean that (probably at the price of a performance penalty) one could
> handle the variable results of getPropName() over time and write (?):
>
> MyEvent(eval (prop1 matches ("This event is for"+getPropName()+" and is sent
> toblah blah blah")))
>
> Best regards,
>
> Bruno.
>
> Wolfgang Laun a écrit :
>
> 2011/1/24 Bruno Freudensprung <bruno.freudensprung at temis.com>
>
>
> MyEvent(prop1 matches eval("This event is for"+getPropName()+" and is sent
> to
> blah blah blah"))
>
>
>
> You cannot use eval() like this. It is a conditional element.
>
> If getPropName() is a function that is constant over time (!) then you
> should be able to
>
>    MyEvent(prop1 matches ("This event is for"+getPropName()+" and is..."))
>
> If you need to match against a value that should change during
> execution, put the value into a fact and make sure to update/modify
> that fact when you change the value:
>
>    MyPattern( $v: value )
>    MyEvent( prop1 matches ("This event is for"+$v +" and is..."))
>
> In both cases, the parentheses around the concatenaion are essential.
>
> -W
>
>
>
>
>
> Best regards,
>
> Bruno.
>
>
> Ayush a écrit :
>
> Hi, I'm trying to implement regular expression using matches. The regular
> expression is dynamic and retrieved from a java function. In my first
> approach I'm tried to call the java function for matches like
>
> MyEvent(prop1 matches "This event is for"+getPropName()+" and is sent to
> blah blah blah")
>
> Now when I try to execute the above expression it gives error as illegal
> statement (I even tried back-slash to escape it). It also gives error like
> "Expecting ')' instead of '(' ".
>
> So I declared a function which takes two string parameters and returns me
> the concatenated one.
> function String concatenate(String str1, String str2) {
> 	return str1+str2;
> }
>
> $matchStr : String() from concatenate("This event is for",getPropName()+"
> and is sent to blah blah blah")
>
> Now when I'm using this variable in my rule it is not getting executed.
> Please note that there is no problem in regex because when I put the regex
> as string (i.e. without using any function to retreive it) it works fine.
>
> MyEvent(prop1 matches $matchStr)
>
> Can anyone please let me know how can I solve it. Thanks in advance.
>
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>




More information about the rules-users mailing list