I have an ftp inbound endpoint where a lot of files are getting stored (not all for me) so I added a filename-regex-filter with the different regular expressions that I want to fetch from the FTP directory:
<file:filename-regex-filter pattern="
                            ${environment}\.TEST.xml,
                            0\.${environment}\.REPD\.(.*).GZ,
                            ${environment}(.*)PERSONNOTI(.*)\.xml\.gz,
                            ${environment}(.*)PERSONNOTI(.*)voucher\.xml" caseSensitive="false" />
This works great, but now I want to execute specific behavior based on the type of file. Therefore I use a choice component with different when expressions:
My first idea was to use a choice component with when expressions that use the same regular expressions that are used in the filename-regex-filter and that are working there:
<when expression="#[message.inboundProperties.originalFilename.matches('0\.${environment}\.REPD\.(.*).GZ')]">
    // Specific behaviour for this type of files
</when>    
This produced following error message:
 Exception stack is:
 1. [Error: illegal escape sequence: .]
 [Near : {... age.inboundProperties.originalFilename.matches('0\.T\.REPD\.(.*).GZ') ....}]
                                                              ^
 [Line: 1, Column: 55] (org.mule.api.expression.InvalidExpressionException) 
  org.mule.el.mvel.MVELExpressionLanguage:238(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/InvalidExpressionException.html)
 2. [Error: illegal escape sequence: .]
 [Near : {... age.inboundProperties.originalFilename.matches('0\.T\.REPD(.*).GZ') ....}]     
This means the expression attribute doensn't expect escape characters, so I decided not to escape them
<when expression="#[message.inboundProperties['originalFilename'].matches('${environment}.TEST.xml')]">
    //Specific behavior for this type of files...          
</when>
<when expression="#[message.inboundProperties.originalFilename.matches('0.${environment}.REPD.*.GZ')]">
    //Specific behavior for this type of files...
</when>
<otherwise>
    <file:outbound-endpoint path="C:/test/result/other" responseTimeout="10000" outputPattern="#[message.inboundProperties.originalFilename]"/>
</otherwise> 
Here the message is always routed towards the otherwise clause, except for the first expression where no wildcards are used...
Is it a good practice to work with a when expressions, and what is the correct way of putting the expression?
