[rules-users] Problem implementing dynamic regular expression

Wolfgang Laun wolfgang.laun at gmail.com
Mon Jan 24 09:40:11 EST 2011


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
>




More information about the rules-users mailing list