You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by neo anderson <ja...@yahoo.co.uk> on 2008/03/11 16:13:00 UTC

using RE with newline problem

I use ant script to load a file similar to build.properties. (its format
looks like 'key = value')

One of its value looks like key = 'value' (value surrounded with the single
quotes)

So I use filterchain to get rid of it, code snippet as follow:

        <loadfile srcfile="file.txt" property="temp.param">
                <filterchain>
                        <linecontains>
                                <contains value="key = "/>
                        </linecontains>
                        <tokenfilter>
                                <stringtokenizer delims="="/>
                                <replaceregex pattern="('{1})" replace=""/>
                                <replaceregex pattern="('{1})" replace=""/>
                                <replaceregex pattern="key" replace=""/>
                                <replaceregex pattern="${line.separator}"
replac
e="" /><!-- newly added line to eliminate new line or CR -->
                        </tokenfilter>
                        <tokenfilter>
                                <replacestring from="=" to=""/>
                        </tokenfilter>
                        <trim/>
                </filterchain>
        </loadfile>

However, after sending parameter to the ant task it fails. Then I discover
the value of temp.param contain the newline (or carriage return). The output
using '<echo message="[${temp.param}]"/>' is as follow:

     [echo] [value
     [echo] ]

The value I expect is [value] not [value\n]. 

I try to use '<replaceregex pattern="${line.separator}" replace="" />', but
it does not work at all.

What should I do in order to get rid of it.

-- 
View this message in context: http://www.nabble.com/using-RE-with-newline-problem-tp15976680p15976680.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org