Replacing multiple occurrence of double/single quotes using Ant's replaceregexp

D

Darpan

Hi,

I am trying to write a task to replace all occurrences of single and
double quotes on a line starting with a "*" to a "\"" or "\'".
Basically i want to escape the double\single quotes. My code works for
only the first occurrence of a single or double quote and cant get it
to work for multiple occurrences of the quotes. This is what I have
done so far

<project name="Replace Example" default="doublequotes" basedir=".">
<target name="doublequotes" description="Replaces occurence of">
<replaceregexp file= "test.txt" byline="true">
<regexp pattern="(\*.*)(\p{Punct})"/>
<substitution expression="\1\\$2" />
</replaceregexp >

</target>
</project>

My test.txt contains the following lines

* Hello the"re
* Hello t'here
"Hello there"
* "Hello there"

I am executing ant using the following command
ant -f double_quotes.xml
-Dant.regexp.regexpimpl=org.apache.tools.ant.util.regexp.JakartaOroRegexp


Any help will be highly appreciated. Thanks in advance.

Darpan
 
T

Tilman Bohn

Hi,

I am trying to write a task to replace all occurrences of single and
double quotes on a line starting with a "*" to a "\"" or "\'".
Basically i want to escape the double\single quotes. My code works for
only the first occurrence of a single or double quote and cant get it
to work for multiple occurrences of the quotes. This is what I have
done so far

<project name="Replace Example" default="doublequotes" basedir=".">
<target name="doublequotes" description="Replaces occurence of">
<replaceregexp file= "test.txt" byline="true">
[...]

Add the attribute flags="g" to that and you should be all set. This does
the same as sed/perl's g (global) flag.
 
R

Rhino

Darpan said:
Hi,

I am trying to write a task to replace all occurrences of single and
double quotes on a line starting with a "*" to a "\"" or "\'".
Basically i want to escape the double\single quotes. My code works for
only the first occurrence of a single or double quote and cant get it
to work for multiple occurrences of the quotes. This is what I have
done so far

<project name="Replace Example" default="doublequotes" basedir=".">
<target name="doublequotes" description="Replaces occurence of">
<replaceregexp file= "test.txt" byline="true">
<regexp pattern="(\*.*)(\p{Punct})"/>
<substitution expression="\1\\$2" />
</replaceregexp >

</target>
</project>

My test.txt contains the following lines

* Hello the"re
* Hello t'here
"Hello there"
* "Hello there"

I am executing ant using the following command
ant -f double_quotes.xml
-Dant.regexp.regexpimpl=org.apache.tools.ant.util.regexp.JakartaOroRegexp


Any help will be highly appreciated. Thanks in advance.
The Ant mailing list may be a better place to ask this kind of question.
While there are some Ant users on comp.lang.java.programmer, the Ant user
mailing list is specifically focused on Ant questions like yours. The people
there are very helpful.

You can subscribe at http://ant.apache.org/mail.html.

Rhino
 
D

Darpan

Thank you for your suggestions Tilman and Rhino. Tilman i did try the
flags="g" option but no change. Only one occurrence of the quote is
being replaced per line.

I'll try the Ant mailing list if I can find something there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top