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

Discussion in 'Java' started by Darpan, Mar 1, 2005.

  1. Darpan

    Darpan Guest

    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
     
    Darpan, Mar 1, 2005
    #1
    1. Advertising

  2. Darpan

    Tilman Bohn Guest

    In message <>,
    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
     
    Tilman Bohn, Mar 1, 2005
    #2
    1. Advertising

  3. Darpan

    Rhino Guest

    "Darpan" <> wrote in message
    news:...
    > 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
     
    Rhino, Mar 1, 2005
    #3
  4. Darpan

    Darpan Guest

    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.
     
    Darpan, Mar 2, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris White

    Quotes/Double Quotes in Image Control

    Chris White, Sep 22, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,853
    Hermit Dave
    Sep 22, 2004
  2. Chris
    Replies:
    1
    Views:
    13,647
    Oisin
    Mar 24, 2006
  3. Victor
    Replies:
    0
    Views:
    8,847
    Victor
    Sep 1, 2004
  4. Sydex
    Replies:
    12
    Views:
    6,505
    Victor Bazarov
    Feb 17, 2005
  5. jOhn
    Replies:
    1
    Views:
    227
    Phlip
    Jan 29, 2008
Loading...

Share This Page