[rules-users] capturing matches from regular expressions?

Edson Tirelli tirelli at post.com
Sat Sep 22 11:24:44 EDT 2007


    At this time, there is no such feature. May I ask you please to open a
JIRA feature request for it?
    The way I see it, we would need to create a feature to allow binding of
variables to arbitrary expressions in the LHS and allow this binds to be
used in the RHS.

    []s
    Edson

2007/9/22, Godmar Back <godmar at gmail.com>:
>
> On 9/22/07, Edson Tirelli <tirelli at post.com> wrote:
> >
> >    Sorry, nope. Is there a use case for that?
> >
>
> For instance, I'd like to write a rule where I need to be alerted of
> all facts where a specific field is of the form "(.*)Suffix".  The
> action I'm then taking requires the "(.*)" as a parameter.
> The value of "Suffix" does not matter to the action and should be
> restricted to the .drl file (as it matters there only.)
>
> If I cannot capture the match, I will have to pay both a cost in
> runtime and in expressiveness. In runtime because the regular
> expression match is repeated in the action.
> In expressiveness, because my code is now less localized since there
> will be 2 places that deal with "Suffix".  If I repeated "Suffix" in
> the match and action as a string literal, changing it would require
> changing it in two places:
>
> when  n : Name (value matches "(.*)Suffix")
> then   TakeAction(n, "Suffix")
>
> I do not know if I could use a variable, as in
>
> final String suffix = "Suffix";
> when  n : Name (value matches ("(.*)" + suffix))
> then   TakeAction(n, suffix)
>
> but even then, the code is less expressive and the match would need to
> repeated; in any event, I'd like to be able to write something along
> the lines of:
>
> when  n : Name (value matches "(.*)Suffix")   .... some way to bind
> "presuffix" to $1 ....
> then   TakeAction(presuffix)
>
> where "presuffix" captures $1 in the match. This way, I'd have to
> change "Suffix" only once.
>
> - Godmar
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070922/747bb1a8/attachment.html 


More information about the rules-users mailing list