Regex Mule表达式正则表达式问题

Regex Mule表达式正则表达式问题,regex,expression,mule,Regex,Expression,Mule,我有一个ftp入站端点,其中存储了大量文件(并非所有文件),因此我添加了一个文件名正则表达式过滤器,其中包含我要从ftp目录获取的不同正则表达式: <file:filename-regex-filter pattern=" ${environment}\.TEST.xml, 0\.${environment}\.REPD\.(.*).GZ,

我有一个ftp入站端点,其中存储了大量文件(并非所有文件),因此我添加了一个文件名正则表达式过滤器,其中包含我要从ftp目录获取的不同正则表达式:

<file:filename-regex-filter pattern="
                            ${environment}\.TEST.xml,
                            0\.${environment}\.REPD\.(.*).GZ,
                            ${environment}(.*)PERSONNOTI(.*)\.xml\.gz,
                            ${environment}(.*)PERSONNOTI(.*)voucher\.xml" caseSensitive="false" />
这意味着expression属性不需要转义字符,所以我决定不转义它们

<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> 

//此类型文件的特定行为。。。
//此类型文件的特定行为。。。
在这里,消息总是路由到otherwise子句,除了第一个表达式没有使用通配符


使用when表达式是一种好的做法吗?使用when表达式的正确方法是什么?

我找到了一种目前有效的解决方案,但我认为使用正则表达式肯定有更好的解决方案:

<file:inbound-endpoint responseTimeout="10000" connector-ref="input" path="C:/test">
        <file:filename-regex-filter pattern="
                            0\.${environment}\.REPD\.(.*).GZ,
                            ${environment}(.*)PERSONNOTI(.*)\.xml\.gz,
                            ${environment}(.*)PERSONNOTI(.*)voucher\.xml" caseSensitive="false" />
    </file:inbound-endpoint>
    <choice>
        <when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('0.${environment}.REPD'.toLowerCase()) &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).endsWith('gz')]">
            <gzip-uncompress-transformer/>
            // Specific behaviour for this type of files 
        </when>
        <when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('${environment}'.toLowerCase()) &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).contains('personnoti') &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).endsWith('.xml.gz')]">
            // Specific behaviour for this type of files
        </when>
        <when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('${environment}'.toLowerCase()) &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).contains('personnoti') &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).endsWith('voucher.xml')]">
            // Specific behaviour for this type of files
        </when>
    </choice>

//此类型文件的特定行为
//此类型文件的特定行为
//此类型文件的特定行为

我在网上搜索了几个小时,但没有找到解决我问题的有效方法。如果有人知道如何使用正则表达式或其他计算器来解决这个问题,我很好奇…

我找到了一个目前有效的解决方案,但我认为一定有一个使用正则表达式的更好的解决方案:

<file:inbound-endpoint responseTimeout="10000" connector-ref="input" path="C:/test">
        <file:filename-regex-filter pattern="
                            0\.${environment}\.REPD\.(.*).GZ,
                            ${environment}(.*)PERSONNOTI(.*)\.xml\.gz,
                            ${environment}(.*)PERSONNOTI(.*)voucher\.xml" caseSensitive="false" />
    </file:inbound-endpoint>
    <choice>
        <when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('0.${environment}.REPD'.toLowerCase()) &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).endsWith('gz')]">
            <gzip-uncompress-transformer/>
            // Specific behaviour for this type of files 
        </when>
        <when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('${environment}'.toLowerCase()) &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).contains('personnoti') &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).endsWith('.xml.gz')]">
            // Specific behaviour for this type of files
        </when>
        <when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('${environment}'.toLowerCase()) &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).contains('personnoti') &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).endsWith('voucher.xml')]">
            // Specific behaviour for this type of files
        </when>
    </choice>

//此类型文件的特定行为
//此类型文件的特定行为
//此类型文件的特定行为

我在网上搜索了几个小时,但没有找到解决我问题的有效方法。如果有人知道如何使用正则表达式或其他计算器来解决这个问题,我很好奇…

您的输入与正则表达式混合,因此如果您在输入中包含这些正则表达式特殊字符,它们最终会破坏正则表达式的语法。因此,您需要将它们正确地放入现有的正则表达式中,或者将它们全部转义:
*
\*
.
[
\[
,`\`to`\\\\`等等..也许您的语言已经有了类似于
regex.escape()的东西
方法,就像其他语言一样。然后在输入序列中使用它。请将它从注释移动到问题(包括用于转义的代码)这将使您的问题在您迄今为止的研究中更加完整,并且更容易被了解这一领域的人回答。您的输入与正则表达式混合,因此如果在输入中包含这些正则表达式特殊字符,它们最终会破坏正则表达式的语法。因此,您需要将它们正确地放入现有的正则表达式中,或者全部转义:
*
\*
.
[
\[
,``到`\\\`等等..也许你的语言已经有了类似于
Regex.escape()的东西
方法与其他一些语言一样。然后在输入序列中使用它。请将它从注释移到问题(包括用于转义的代码)中。这将使您的问题更完整,更便于了解此领域的人回答。
<file:inbound-endpoint responseTimeout="10000" connector-ref="input" path="C:/test">
        <file:filename-regex-filter pattern="
                            0\.${environment}\.REPD\.(.*).GZ,
                            ${environment}(.*)PERSONNOTI(.*)\.xml\.gz,
                            ${environment}(.*)PERSONNOTI(.*)voucher\.xml" caseSensitive="false" />
    </file:inbound-endpoint>
    <choice>
        <when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('0.${environment}.REPD'.toLowerCase()) &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).endsWith('gz')]">
            <gzip-uncompress-transformer/>
            // Specific behaviour for this type of files 
        </when>
        <when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('${environment}'.toLowerCase()) &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).contains('personnoti') &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).endsWith('.xml.gz')]">
            // Specific behaviour for this type of files
        </when>
        <when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('${environment}'.toLowerCase()) &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).contains('personnoti') &amp;&amp;
                        (message.inboundProperties.originalFilename.toLowerCase()).endsWith('voucher.xml')]">
            // Specific behaviour for this type of files
        </when>
    </choice>