Hide Forgot
Help Desk Ticket Reference: https://c.na7.visual.force.com/apex/Case_View?id=500A00000045vTnIAI&sfdc.override=1 Steps to Reproduce: Use the java code from Drools Project provided by JBossTools or JBDS. The rule: //this regex search for 2 letters + 3 numbers + 2 letters, like: "ab123cd" rule "Regex-A" when $message: Message(message matches "\w\w\d{3}\w\w") then System.out.println( "Regex-A working" ); end //this regex search for 2 letters + 3 numbers + 2 letters, like: "ab123cd" rule "Regex-B" when $message: Message(message matches "\\w\\w\\d{3}\\w\\w") then System.out.println( "Regex-B working" ); end //this regex search for 2 letters + 3 numbers + 2 letters, like: "ab123cd" rule "Regex-C" when $message: Message(message.toString matches "\w\w\d{3}\w\w") then System.out.println( "Regex-C working" ); end Only Regex-C and Regex-B works. Workaround Description: Use escapes like: Cheese( type matches "(Buffalo)?\\S*Mozarella" ) or toString Cheese( type.toString matches "(Buffalo)?\\S*Mozarella" ) securitylevel_name: Public 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")
drools-simple-regex.zip is a sample project to simulate that.
Attachment: Added: drools-simple-regex.zip
Link: Added: This issue is a dependency of JBRULES-2745
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 ...
Draft text for release notes states: https://jira.jboss.org/browse/BRMS-412 There was a problem with the use of escapes when using the "matches"operator. The drools.parser.processStringEscapesoption has been added. Use of this feature means that matched patterns do not have to be escaped.
Writer: Added: dlesage
Release Notes Docs Status: Added: Documented as Resolved Issue
Release Notes Text: Added: test
Release Notes Text: Removed: test
Release Notes Text: Added: There was a problem with the use of escapes when using the "matches"operator. The drools.parser.processStringEscapesoption has been added. Use of this feature means that matched patterns do not have to be escaped.
David, you have to set the drools.parser.processStringEscapes property to false in order for escapes not to be needed.