You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by momo momo <mo...@hotmail.com> on 2003/12/17 16:23:18 UTC
RE: replacing commented text - Regexp
Hi,
first of all, thank you for your help I really appreciate it.
but I am now stuck with another problem:
I have the file:
#Jdbc
#environnement A :
#project.key1=123
#project.system.key2=ABD
#comment: bla bla bla bla
and I would like to delete the "#" char in front of the line that begins by
"project"
to have that:
#Jdbc
#environnement A :
project.key1=123
project.system.key2=ABD
#comment: bla bla bla bla
so I use a thing that works but I am not really satisfied:
In my Ant file I use 2 similar targets that calls each other (because a
target cannot call itself!) and remove a "#" each time they are executed.
The stop condition is the matchfile condition, I test if the file has benn
change. It is not pretty nice, just take a look:
<target name="decomment" unless="file.match">
<copy file="${workdir}\Test.txt" tofile="${workdir}\Test3.txt"
overwrite="true"/>
<replaceregexp file="${workdir}\Test.txt"
match="(.*)#(project.*)"
replace="\1\2"
flags="s"
/>
<condition property="file.match">
<filesmatch file1="${workdir}\Test.txt" file2="${workdir}\Test3.txt"/>
</condition>
<antcall target="decomment2"/>
</target>
<target name="decomment2" unless="file.match">
<copy file="${workdir}\Test.txt" tofile="${workdir}\Test3.txt"
overwrite="true"/>
<replaceregexp file="${workdir}\Test.txt"
match="(.*)#(project.*)"
replace="\1\2"
flags="s"
/>
<condition property="file.match">
<filesmatch file1="${workdir}\Test.txt" file2="${workdir}\Test3.txt"/>
</condition>
<antcall target="decomment"/>
</target>
so I wonder if there is not anotherway to do that?
Momo
_________________________________________________________________
MSN Messenger http://g.msn.fr/FR1001/866 : dialoguez en direct et
gratuitement avec vos amis !
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: replacing commented text - Regexp
Posted by Peter Reilly <pe...@corvil.com>.
You need to use the "g" flag to replace all the occuances.
Peter
momo momo wrote:
> Hi,
> first of all, thank you for your help I really appreciate it.
>
> but I am now stuck with another problem:
> I have the file:
>
> #Jdbc
> #environnement A :
> #project.key1=123
> #project.system.key2=ABD
> #comment: bla bla bla bla
>
> and I would like to delete the "#" char in front of the line that
> begins by "project"
> to have that:
>
> #Jdbc
> #environnement A :
> project.key1=123
> project.system.key2=ABD
> #comment: bla bla bla bla
>
> so I use a thing that works but I am not really satisfied:
> In my Ant file I use 2 similar targets that calls each other (because
> a target cannot call itself!) and remove a "#" each time they are
> executed. The stop condition is the matchfile condition, I test if the
> file has benn change. It is not pretty nice, just take a look:
>
> <target name="decomment" unless="file.match">
> <copy file="${workdir}\Test.txt" tofile="${workdir}\Test3.txt"
> overwrite="true"/>
> <replaceregexp file="${workdir}\Test.txt"
> match="(.*)#(project.*)"
> replace="\1\2"
> flags="s"
> />
> <condition property="file.match">
> <filesmatch file1="${workdir}\Test.txt"
> file2="${workdir}\Test3.txt"/>
> </condition>
> <antcall target="decomment2"/>
> </target>
>
>
> <target name="decomment2" unless="file.match">
> <copy file="${workdir}\Test.txt" tofile="${workdir}\Test3.txt"
> overwrite="true"/>
> <replaceregexp file="${workdir}\Test.txt"
> match="(.*)#(project.*)"
> replace="\1\2"
> flags="s"
> />
> <condition property="file.match">
> <filesmatch file1="${workdir}\Test.txt"
> file2="${workdir}\Test3.txt"/>
> </condition>
> <antcall target="decomment"/>
> </target>
>
> so I wonder if there is not anotherway to do that?
> Momo
>
> _________________________________________________________________
> MSN Messenger http://g.msn.fr/FR1001/866 : dialoguez en direct et
> gratuitement avec vos amis !
>
>
> ---------------------------------------------------------------------
> 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