Bug 57293 - Substitutions containing \( are replaced by (
Summary: Substitutions containing \( are replaced by (
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.9.4
Hardware: PC Mac OS X 10.4
: P2 major (vote)
Target Milestone: ---
Assignee: Ant Notifications List
Depends on:
Reported: 2014-12-01 18:45 UTC by Lyn Headley
Modified: 2014-12-02 17:17 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Lyn Headley 2014-12-01 18:45:22 UTC
given file prep.js with contents:

and the following build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="abc" default="build">
  <target name="build">
    <replaceregexp file="./prep.js"


running "ant" results in prep.js containing:

rather than the expected:

We ran into this bug in a production system using replaceregexp to insert the contents of one file into another. This method is widely recommended on the webs and will fail for any file containing, e.g. a regular expression matching a parenthesis (e.g. the javascript /\(/).
Comment 1 Jan Mat 2014-12-02 07:51:51 UTC
The problem is that the \ starts a backreference (like \1) so it must be quotet.
Four slashes ...

This one works for me:

    <target name="testMatching_Bug57293">
        <mkdir dir="${output}"/>
        <echo file="${output}/text.txt">Hello, world!</echo>
        <replaceregexp match="(\w*)" replace="\\\\(abcd\\\\)">
          <file file="${output}/text.txt"/>
           resource="${output}/text.txt" value="\(abcd\), world!"/>
Comment 2 Lyn Headley 2014-12-02 17:17:03 UTC
I am now thinking this should simply be mentioned in the documentation, as various people are using replaceregexp (in combination with loadfile) to insert files into other files, and I don't see any awareness of this issue among them.