ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From luis.cone...@ge.com
Subject RE: backslash and CRLF in regular expression [solution]
Date Wed, 23 Jun 2004 15:17:31 GMT
Hi all,

	Finally, I came up with following target:
	(I am using ant-contrib's <for> task)
--------------------------------------------------
    <target name="replace">
        <for param="file">
            <path>
                <!--Defines which files will be used-->
                <fileset dir="${basedir}/schema/initial_data">
                    <include name="**/*"/>
                    <exclude name="**/*.xml"/>
                </fileset>
            </path>
            <sequential>
                <echo>current file is @{file} </echo>
                <echo>Scanning for replacement </echo>
                <!-- Remove backslash + line separator characters-->
       	    <replaceregexp flags="g" file="@{file}">
		        <regexp pattern="\\${line.separator}"/>
		        <substitution expression=""/>
		    </replaceregexp>
		    <!-- Remove extra spaces -->
		    <replaceregexp match="\s+" replace=" " flags="g"
byline="true" file="@{file}"/>
            </sequential>
        </for>
    </target>
--------------------------------------------------

	With this target I was able to remove the backslash+CRLF characters
and remove the tabs / extra spaces resultant from the prior operation.

	Thanks to Stefan, Johan, Peter, Ivan for your advices. Your comments
were very helpful.

	Regards.

	Luis Conelly

-----Original Message-----
From: Stefan Bodewig [mailto:bodewig@apache.org]
Sent: Wednesday, June 23, 2004 1:11 AM
To: user@ant.apache.org
Subject: Re: backslash and CRLF in regular expression


On Tue, 22 Jun 2004, luis conelly <luis.conelly@ge.com> wrote:
> Hi all,
> 
> 	It turns out that I have these files that have several lines
> 	like following:
> 
> blablabla blabla bla \
> blablabla blabla bla \
> blablabla blabla bla;
> 
> and I want to make a single line like:
> 
> blablabla blabla bla blablabla blabla bla blablabla blabla bla;
> 
> I have tried this:
> 
>     <target name="replace">
>         <replaceregexp byline="true" file="myfile">
> 	    <regexp pattern="\\&#13;&#10;"/>
>           <substitution expression=""/>
>          </replaceregexp>
>     </target>

byline="true" is probably destroying all your attempts since this will
match patterns against each line and strip the CR and LF characters.
Try byline="false".  Oh, and I'd probably use ${line.separator}
instead of &#13;&#10; for easier portability.

Stefan

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

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


Mime
View raw message