[jboss-jira] [JBoss JIRA] Resolved: (JBRULES-2745) Problems in the use of escapes in the "matches" operator

Tihomir Surdilovic (JIRA) jira-events at lists.jboss.org
Thu Oct 21 22:32:54 EDT 2010


     [ https://jira.jboss.org/browse/JBRULES-2745?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tihomir Surdilovic resolved JBRULES-2745.
-----------------------------------------

    Fix Version/s: 5.2.0.M1
       Resolution: Done


With this change, using complex types or simple types by default you still have to escape the matching pattern, for example:

when
		$task : BinTask( $bn : bin.name matches "\\w\\w\\d{3}\\w\\w" )
		$bin : Bin( $nm : name  matches "\\w\\w\\d{3}\\w\\w" ) 
then
...

If you set the drools.parser.processStringEscapes option:
KnowledgeBuilderConfiguration kbconf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
		kbconf.setProperty("drools.parser.processStringEscapes", "false");
		
		KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kbconf);
		
...

the matches patterns do not have to be escaped, and the patterns can be:

when
		$task : BinTask( $bn : bin.name matches "\w\w\d{3}\w\w" )
		$bin : Bin( $nm : name  matches "\w\w\d{3}\w\w" ) 
then
...

> Problems in the use of escapes in the "matches" operator
> --------------------------------------------------------
>
>                 Key: JBRULES-2745
>                 URL: https://jira.jboss.org/browse/JBRULES-2745
>             Project: Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>    Affects Versions: 5.1.1.FINAL
>            Reporter: Alessandro Lazarotti
>            Assignee: Tihomir Surdilovic
>             Fix For: 5.2.0.M1
>
>         Attachments: drools-simple-regex.zip
>
>
> According to official documentation, it is not necessary to use escapes:
> "In contrast to Java, escapes are not needed within regular expressions written as string literals." (a note in topic 4.8.2.1.5.)
> But it is not true. Actually even the example of the documentation does not work if you do not use escape:
> //type is a String
> Cheese( type matches "(Buffalo)?\S*Mozarella" )
> ... should be changed to:
> //type is a String
> Cheese( type matches "(Buffalo)?\\S*Mozarella" )
> Curiously, if you have a attribute of the attribute which matches a regex, you shouldn't use escapes:
> //type is "complex type" and value is a String
> Cheese( type.value matches "(Buffalo)?\S*Mozarella" )
> ... it's work!
> That said, a workaround to work with simple String attributes, you should use "toString":
> //type is "String" 
> Cheese( type.toString matches "(Buffalo)?\S*Mozarella")

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jboss-jira mailing list