Great! I will try out. Thank you so much for your detail explanation!

 

Stacy

 

From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Wolfgang Laun
Sent: Thursday, March 27, 2014 11:33 AM
To: Rules Users List
Subject: Re: [rules-users] How to do word match in drools?

 

See inline.

 

On 27 March 2014 16:59, Yuan, Stacy [DBA] <stacyy@telenav.com> wrote:

Hi,

I am new to this area. Thank you very much for your reply!

This is current script

brandName matches "(?i)(.*cyber.*|.*internet.*|.*pizza.*|.*restaurant.*|.*sushi.*)

So this  matches every string containing sushi.

Joa Sushie Café
Java Sushi
Sushi Blvd
Japanese Sushi Bar

 

This is to be expected: each of these 4 lines contains "sushi".

 


But I only want to match the word sushi. This means " Joa Sushie Café" will not be included.

Actually I am looking for word match. What is the best way to include above words?

 

All regular expressions I know have a way for expressing the concept "word boundary".

This is a zero-length assumption (or "anchor"), that matches a transition from a word character
to a non-word character. (Note that the definition of "word character" may not *always*

meet your expectations, but it should in this case.)

 


brandName == "(?i)(.*cyber.*|.*internet.*|.*pizza.*|.*restaurant.*|.*sushi.*)???

 

(The "==" is bad: you want to do a pattern match.) OK, to restrict the "sushi" to the
real thing (assuming the final "???" aren't relevant):

    brandName matches "(?i)(...|... ...|\\bsushi\\b)"

 

"\b" is the word boundary anchor, and you have to duplicate the backslash, as in Java.
 If the same borderline case should hold for pizza and others, you could use

    brandName matches "(?i).*\\b(cyber|internet|pizza|restaurant|sushi)\\b.*"

 

All of this is untested, but it shouldn't be very far off the mark.

-W

 


Best

Stacy

-----Original Message-----
From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Wolfgang Laun
Sent: Thursday, March 27, 2014 12:26 AM
To: Rules Users List
Subject: Re: [rules-users] How to do word match in drools?

You can use == to compare strings.

For a more comprehensive answer, ask a more detailed question.

-W

On 26/03/2014, Yuan, Stacy [DBA] <stacyy@telenav.com> wrote:
> For example,  word sushi
> I do not want sushie show up and shsushi show up when we do drools match.
>
> Thanks
> Stacy
>
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users