Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Replacing multiple occurrence of double/single quotes using Ant's replaceregexp

Reply
Thread Tools

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

 
 
Darpan
Guest
Posts: n/a
 
      03-01-2005
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.r egexp.JakartaOroRegexp


Any help will be highly appreciated. Thanks in advance.

Darpan
 
Reply With Quote
 
 
 
 
Tilman Bohn
Guest
Posts: n/a
 
      03-01-2005
In message <(E-Mail Removed) >,
Darpan wrote on 28 Feb 2005 21:29:42 -0800:

> 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.

--
Cheers, Tilman

`Boy, life takes a long time to live...' -- Steven Wright
 
Reply With Quote
 
 
 
 
Rhino
Guest
Posts: n/a
 
      03-01-2005

"Darpan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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.r egexp.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


 
Reply With Quote
 
Darpan
Guest
Posts: n/a
 
      03-02-2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Asp.NET Javascript string, want to pass '(single quotes' within '(single quotes) Chris ASP .Net 1 03-24-2006 09:03 PM
anttask ReplaceRegExp and empty lines ogmios01@gmail.com Java 7 03-19-2006 07:15 PM
Quotes/Double Quotes in Image Control Chris White ASP .Net 1 09-22-2004 06:22 AM
Re: Problem in ant replace task and replaceregexp task to update xml Victor Java 0 09-01-2004 03:58 AM
Multiline quotes - escaping quotes - et al Lawrence Tierney Java 3 12-24-2003 05:12 PM



Advertisments