[rules-users] mvel regex not working???

Carlsen, Len len.carlsen at ubc.ca
Thu Nov 15 19:29:01 EST 2007


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 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20071115/c7159336/attachment.html 


More information about the rules-users mailing list