You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Bin Chen <bi...@bea.com> on 2003/01/14 23:07:28 UTC
Help with Replace regexp with ant 1.5
Hi, I am trying to use the replaceregexp task of ant 1.5 to match and
replace certain patterns, here is the sample:
<replaceregexp
file="${Dest}/sample.cmd">
<regexp pattern=":_sample_command_marker"/>
<substitution expression="@rem my substitution \n set
CMD_HOME=@MY_HOME\mysample"/>
</replaceregexp>
Here "\n" is supposed to be a newline, and "\" in CMD_HOME is supposed to be
a direcory
However, when the substitution occured, all back slashes were taken out,
even when I tried using "\\n" and "\\", they were still taken out. Any idea
what happend there?
BTW, I am using jdk1.4.1_01 and jakarta ORO and jakarta regexp as
recommended by the ant document.
Your help is greatly appreciated.
Bin
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Help with Replace regexp with ant 1.5
Posted by Bin Chen <bi...@bea.com>.
The regexpreplace task took the "\\" and returned with nothing. It also
happened to $ and other meta charactors. It seems to me that doubling up the
meta charactors does not really work as it did in Java code. Is this a bug
or I simply missed something completely?
Thank you very much!!
Bin
-----Original Message-----
From: Stefan Bodewig [mailto:bodewig@apache.org]
Sent: Friday, January 31, 2003 3:02 AM
To: ant-user@jakarta.apache.org
Subject: Re: Help with Replace regexp with ant 1.5
Sorry for the late reply
On Thu, 16 Jan 2003, Bin Chen <bi...@bea.com> wrote:
> <replaceregexp file="${MYDir}/mycommand.cmd">
> <regexp pattern=":_insertpathhere"/>
> <substitution expression="@rem My path 

> set MY_HOME=@ROOT@#x5c;mybindir"/>
> </replaceregexp>
>
> Here is the output I expect to have
> @rem My path
> set MY_HOME=@ROOT\mybindir
>
> What I got with the about <replaceregexp> is
> @rem My path
> set MY_HOME=@ROOTmybindir
What do you get if you simply use \\ instead of \ in above
substitution?
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: ant-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ant-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: ant-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ant-user-help@jakarta.apache.org
Re: Help with Replace regexp with ant 1.5
Posted by Stefan Bodewig <bo...@apache.org>.
Sorry for the late reply
On Thu, 16 Jan 2003, Bin Chen <bi...@bea.com> wrote:
> <replaceregexp file="${MYDir}/mycommand.cmd">
> <regexp pattern=":_insertpathhere"/>
> <substitution expression="@rem My path 

> set MY_HOME=@ROOT@#x5c;mybindir"/>
> </replaceregexp>
>
> Here is the output I expect to have
> @rem My path
> set MY_HOME=@ROOT\mybindir
>
> What I got with the about <replaceregexp> is
> @rem My path
> set MY_HOME=@ROOTmybindir
What do you get if you simply use \\ instead of \ in above
substitution?
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: ant-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ant-user-help@jakarta.apache.org
RE: Help with Replace regexp with ant 1.5
Posted by Bin Chen <bi...@bea.com>.
Stephan,
What I am trying to do is to use a command template file and looking for the
marker and substitute it with a set PATH.
Here is the code nip of my <replaceregexp>
<target name="doregexp" depends="init" description="substitute the path into
the cmd file">
<replaceregexp
file="${MYDir}/mycommand.cmd">
<regexp pattern=":_insertpathhere"/>
<substitution expression="@rem My path 

set MY_HOME=@ROOT@#x5c;mybindir"/>
</replaceregexp>
</target>
Here is the piece of the template I am using:
:_insertpathhere
Here is the output I expect to have in the command file under
${MYDir}/mycommand.cmd
@rem My path
set MY_HOME=@ROOT\mybindir
What I got with the about <replaceregexp> is
@rem My path
set MY_HOME=@ROOTmybindir
Hope these are making sense to you.
Thank you very much,
Bin
-----Original Message-----
From: Stefan Bodewig [mailto:bodewig@apache.org]
Sent: Thursday, January 16, 2003 12:17 AM
To: ant-user@jakarta.apache.org
Subject: Re: Help with Replace regexp with ant 1.5
On Wed, 15 Jan 2003, Bin Chen <bi...@bea.com> wrote:
> Running with -debug flag, ant did give the message of substituted
> pattern "\" as expected, but the output still did have "\" shown. Is
> this a bug?
Could you give us the complete <replaceregexp> task you use, a sample
of what you want to translate, what you want as output and what you
actually get?
Stefan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Help with Replace regexp with ant 1.5
Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 15 Jan 2003, Bin Chen <bi...@bea.com> wrote:
> Running with -debug flag, ant did give the message of substituted
> pattern "\" as expected, but the output still did have "\" shown. Is
> this a bug?
Could you give us the complete <replaceregexp> task you use, a sample
of what you want to translate, what you want as output and what you
actually get?
Stefan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Help with Replace regexp with ant 1.5
Posted by Bin Chen <bi...@bea.com>.
Stephan: Thanks for your tips. The newline works now with the unicode.
However, the backslash still does not work even with "\". Running
with -debug flag, ant did give the message of substituted pattern "\" as
expected, but the output still did have "\" shown. Is this a bug?
Thanks again,
Bin
-----Original Message-----
From: Stefan Bodewig [mailto:bodewig@apache.org]
Sent: Wednesday, January 15, 2003 7:19 AM
To: ant-user@jakarta.apache.org
Subject: Re: Help with Replace regexp with ant 1.5
On Tue, 14 Jan 2003, Bin Chen <bi...@bea.com> wrote:
> Here "\n" is supposed to be a newline,
use 
 or better ${line.separator} instead. \n doesn't mean
anything special to XML or the regexp engine.
> when the substitution occured, all back slashes were taken out,
doubling them should help - if all else fails, \ is the way to
go.
> BTW, I am using jdk1.4.1_01 and jakarta ORO and jakarta regexp as
> recommended by the ant document.
We recommend to one of them, not all three 8-)
With your setup, JDK 1.4 will take precedence.
Stefan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Help with Replace regexp with ant 1.5
Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 14 Jan 2003, Bin Chen <bi...@bea.com> wrote:
> Here "\n" is supposed to be a newline,
use 
 or better ${line.separator} instead. \n doesn't mean
anything special to XML or the regexp engine.
> when the substitution occured, all back slashes were taken out,
doubling them should help - if all else fails, \ is the way to
go.
> BTW, I am using jdk1.4.1_01 and jakarta ORO and jakarta regexp as
> recommended by the ant document.
We recommend to one of them, not all three 8-)
With your setup, JDK 1.4 will take precedence.
Stefan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>