[rules-users] mvel regex not working???
Edson Tirelli
tirelli at post.com
Fri Nov 16 06:19:42 EST 2007
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 <len.carlsen at ubc.ca>:
>
> 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:* rules-users-bounces at lists.jboss.org [mailto:
> rules-users-bounces at lists.jboss.org] *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 <len.carlsen at ubc.ca>:
>
> 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\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]+)*@[a-zA-Z0-9]([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\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~]+)*@[a-zA-Z0-9]([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 x.x at x.com (valid) and x.xx.com
> (invalid):
>
>
>
> test1-Invalid Email Address: x.xx.com
>
> test2-Invalid Email Address: x.x at x.com
>
> 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
> 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
>
> _______________________________________________
> 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/20071116/e5685cdc/attachment.html
More information about the rules-users
mailing list