Java Mailing List Archive

http://www.ant-tasks.com/

Home » Ant Users List »

using RE with newline problem

Neo Anderson

2008-03-11


Author LoginPost Reply

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.

--
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.