骆驼路线与正则表达式的选择

时间:2012-05-02 15:44:23

标签: regex apache-camel apache-servicemix

我是servicemix / camel的新手,而不是正则表达式中最伟大的,但任何帮助都会感激不尽。

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

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

<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

DONT-匹配度:

Mode|Ref|Name

2 个答案:

答案 0 :(得分:1)

你的正则表达式是正确的,但你需要逃避反斜杠,比如'^[AUD]\\|.*'

答案 1 :(得分:0)

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

我在我的类中添加了“skipFirstLine”注释,并用以下内容替换了整个split xml:

<unmarshal ref="bindyMasterProduct" />