Yes, the drools parser is more restrictive in that point as to avoid
mistakes.
Just a minor comment on your e-mails, this is purely a drools parser
issue, and not an mvel issue. If you select java dialect, but uses the
"matches/not matches" operator, it will be executed by java underneath (not
mvel), but the parser is the one that builds the string to be sent to the
java for processing.
We thought it was much more readable to use non-escaped '\' than doing
it the java way. Imagine some not-so-techie users having to deal with the
sequences of '\' that sometimes we need to deal with in java regexps.
[]s
Edson
2007/11/15, Carlsen, Len <[EMAIL PROTECTED]>:
>
> Thanks a lot Edson. I had escaped characters that don't need to be
> escaped which works in Java but not in mvel (error: no viable alternative at
> character '\').
>
>
>
> Java: "^[a-zA-Z0-9\\#]$"
>
> mvel: "^[a-zA-Z0-9#]$"
>
>
>
> Len
> ------------------------------
>
> *From:* [EMAIL PROTECTED] [mailto:
> [EMAIL PROTECTED] *On Behalf Of *Edson Tirelli
> *Sent:* Thursday, November 15, 2007 7:47 AM
> *To:* Rules Users List
> *Subject:* Re: [rules-users] mvel regex not working???
>
>
>
>
> Len,
>
> When you use code inside eval(), it is executed in the chosen dialect
> (default is java). So, the regexp of your first rule is parsed and executed
> in java and is correct.
> When you use code outside eval(), it is parsed by the Drools parser and
> the drools parser do not require the extra '\' to escape escape-codes. See
> the examples bellow:
>
> java: "^[a-zA-Z0-9\\!\\#\\$\\%\\&]"
> equivalent drools regexp: "^[a-zA-Z0-9\!\#\$\%\&]"
>
> If you change your regexp to use single '\' instead of double, it
> should work fine.
>
> []s
> Edson
>
>
> 2007/11/14, Carlsen, Len <[EMAIL PROTECTED]>:
>
> Hi,
>
>
>
> I have an email validation regex where the mvel matches doesn't seem to
> work. I have created 2 rules where test1 uses the Java String matches and
> test2 uses the mvel matches. Test1 works but test2 doesn't. I am using
> Drools 4.0.3 and JDK 1.6.0_02.
>
>
>
> *rule* "Test1"
>
> *when*
>
> // This works
>
> email : String()
>
> *eval*( !email.* matches*(
> "^[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]+(\\.[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]+)[EMAIL
>
> PROTECTED]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\\.[a-zA-Z]{2,6}$"
> ) )
>
> *then*
>
> System.out.println( "1-Invalid Email Address: " + email );
>
> *end*
>
>
>
> *rule* "Test2"
>
> *when*
>
> // This doesn't work
>
> email : String( toString *not* *matches*
> "^[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]+(\\.[a-zA-Z0-9\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]+)[EMAIL
>
> PROTECTED]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\\.[a-zA-Z]{2,6}$"
> )
>
> *then*
>
> System.out.println( "2-Invalid Email Address: " + email );
>
> *end*
>
>
>
> Here's the output using email addresses [EMAIL PROTECTED] (valid) and x.xx.com
> (invalid):
>
>
>
> test1-Invalid Email Address: x.xx.com
>
> test2-Invalid Email Address: [EMAIL PROTECTED]
>
> test2-Invalid Email Address: x.xx.com
>
>
>
> The regex expressions are exactly the same. Am I doing something wrong
> here?
>
>
>
> Thanks,
>
>
>
> Len
>
>
>
>
> _______________________________________________
> rules-users mailing list
> [email protected]
> 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
>
> _______________________________________________
> rules-users mailing list
> [email protected]
> 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
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users