[rules-users] Problem implementing dynamic regular expression

Bruno Freudensprung bruno.freudensprung at temis.com
Mon Jan 24 09:32:17 EST 2011


Hi,

Can you give a try with the "eval" keyword? Here is a code fragment from 
Drools Expert documentation (Example 4.53), I have the impression (I am 
a Drools beginner) that it can be adapted to your needs:

Person( girlAge : age, sex = "F" )
Person( eval( age == girlAge + 2 ), sex = 'M' )


Maybe something like:

MyEvent(prop1 matches eval("This event is for"+getPropName()+" and is sent to
blah blah blah"))


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.
>
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110124/bcb6e299/attachment.html 


More information about the rules-users mailing list