This is a very nice problem!<br><br>I assume that you have those MyBean facts with one String attribute code inserted and that one String fact is being kicked in. Then the following rule will find the longest match.<br><br>
rule matchLongest<br>when<br>    $string: String()<br>    $myBean: MyBean() from accumulate(<br>       $mb: MyBean( $code: code, eval( $string.startsWith( $mb.getCode() ) ) ),<br>        init( MyBean bestBean = null; int bestLength = 0; )<br>
        action( if( $code.length() &gt; bestLength ){<br>                    bestBean = $mb;<br>                    bestLength = $code.length();<br>                } )<br>        result( bestBean ) )<br>then<br>    System.out.println( &quot;best fit &quot; + $string + &quot; is &quot; + $myBean.getCode() );<br>
    retract( $string );<br>end<br><br>Cheers<br>-W<br><br><br><br><div class="gmail_quote">On 21 July 2011 13:59, esstrata <span dir="ltr">&lt;<a href="mailto:esstrata@yahoo.es">esstrata@yahoo.es</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
<br>
  I hope you can help me out here with a way to implement this rule:<br>
<br>
1) I have String WM<br>
2) I have beans in WM with a property called &#39;code&#39;<br>
public class MyBean {<br>
  private String code;<br>
  ...<br>
<br>
3) I want a rule of the type &quot;Process MyBean with the longest-matching,<br>
not-null code&quot;<br>
<br>
Let explain myself a little further with an example.<br>
<br>
I have the following MyBean objects in WM with the given code properties:<br>
MyBean [code = 44]<br>
MyBean [code = 443]<br>
MyBean [code = 4432]<br>
MyBean [code = 36]<br>
MyBean [code = 7]<br>
<br>
What I want to get is a rule where the following samples would assign to a<br>
variable the given results shown:<br>
4411111 gives MyBean [code = 44]<br>
4433333 gives MyBean [code = 443]<br>
22222 gives null<br>
<br>
I think the rule could start like:<br>
rule &quot;Process MyBean with the longest-matching, not-null code&quot;<br>
        dialect &quot;mvel&quot;<br>
        when<br>
                $s : String()<br>
                $m : MyBean($s matches /the longest not-null possible MyBean.code/)<br>
        then<br>
 ......<br>
<br>
Thank you<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/match-longest-matching-Long-in-WM-tp3188343p3188343.html" target="_blank">http://drools.46999.n3.nabble.com/match-longest-matching-Long-in-WM-tp3188343p3188343.html</a><br>

Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>