1

I am a beginner in .Net and Drools.I am using Drools 3.0 for .Net Application. I am trying to parse data of a variable(Filed:- Subject/Body and Class : -EmailProperties).

Eg:- if Text = "Atal is a .Net Developer and trying for a parser." So I want 'parser' or '.Net' words as output.

I have searched on internet and I found that we can do it by using 'matches' keyword along with regular expression.For that I am using following Regular Expressions: -

rule "Hello"
    when
        //m: EmailProperties(Body.indexOf(".Net"))
        //m: EmailProperties(Body matches  "(?i)(?s)\w.*Developer.*")
        //  m: EmailProperties(Body matches  "/^Developer$/")
        // m: EmailProperties(Subject == "Open Position")
         m: EmailProperties(Subject matches "/^Position$/")
    then
        EmailProperties.debugResult("Hello Brother This is testing for Rules Engine");
end

I followed following link:- regular expression for exact match of a word

Ques : -

1.. What I am doing wrong here?

2.. Is there any other way to achieve parsing using Drools with .Net?

3.. I am using Drools 3 for a .Net application. Do I need to take care about this thing whenever I write regular expression in .Net/Drools or it will be same for everywhere whether it is a java, .Net or any else application?? Does Regular Expressions differ with Technology.

Thanks!!

Community
  • 1
  • 1
Shyam Dixit
  • 2,325
  • 3
  • 19
  • 27

1 Answers1

1

Using the Drools operator matches you don't have to use the anchors ^ and $, as matches (as in Java) pattern-matches the entire target string against the pattern.

If you want to pattern-match with a substring of the target string, you'll have to bracket the pattern with .*. (This means that an arbitrary sequence of characters matches.)

You can do this with indexOf, but you should be aware that this matches even if the string contains a substring containing the one you'd like to find. E.g., indexOf( ".Net" ) will return a nonnegative result if the target string contains, e.g., ".Netstocking".

Parsing with Drools can be achieved in a number of ways. Fishing for strings in a sequence of words (or tokens) may yield surprising results. A very robust way is to cut up a text into words and to process one word after the other. Rules could then match words according to sequence numbers, since, for instance, "green village" is not the same as "village green".

As to your final question: regular expressions differ wildly with technology. Java (and thus Drools) uses a relatively progressive set of wildcards and constructs. Perl is on the bleeding edge. UNIX utilities (grep, awk) are a little back. XQuery 1.0/XPath 2.0 doesn't have all the features Java has. (Things change. Maybe I overlooked a recent development.)

laune
  • 31,114
  • 3
  • 29
  • 42