2

我是 servicemix/camel 的新手,不是最擅长正则表达式的人,但任何帮助都将不胜感激。

我有一个分割文件并通过 bindy 将每一行转换为一个类的路由。这工作正常。但是,我只想要匹配正则表达式的行。

使用http://gskinner.com/RegExr/我检查了我的正则表达式是否匹配测试数据,但是当我运行路由时,所有行都转到“不匹配正则表达式”。

<split>
<tokenize token="\n"/>
<choice>
    <when>
        <!-- Regex: Matches on A, U or D followed by pipe | then ANYTHING, i.e.: A|azz454... -->
        <simple>${body} regex '^[AUD]\|.*'</simple>
        <unmarshal ref="bindyMasterProduct" />
        <log message="OUTPUT: ${body}"/>
    </when>
    <otherwise>
           <log message="Didnt match regex: ${body}"/>
       </otherwise>
</choice>
</split>

正则表达式:

^[AUD]\|.*

匹配:

A|AZZ709256|Cheryl

不要匹配:

Mode|Ref|Name
4

2 回答 2

1

您的正则表达式是正确的,但您需要转义反斜杠,例如'^[AUD]\\|.*'.

于 2012-05-02T16:26:52.733 回答
0

我意识到我以错误的方式解决问题。我不需要在行级别拆分文件,我可以让 bindy 为我做这一切。

我在我的类中添加了“skipFirstLine”注释,并将整个拆分 xml 替换为:

<unmarshal ref="bindyMasterProduct" />
于 2012-05-03T08:14:29.613 回答