Class ReplaceRegExp

java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.optional.ReplaceRegExp
All Implemented Interfaces:
Cloneable

public class ReplaceRegExp extends Task
Performs regular expression string replacements in a text file. The input file(s) must be able to be properly processed by a Reader instance. That is, they must be text only, no binary. The syntax of the regular expression depends on the implementation that you choose to use. The system property ant.regexp.regexpimpl will be the classname of the implementation that will be used (the default is org.apache.tools.ant.util.regexp.JakartaOroRegexp and requires the Jakarta Oro Package).
 Available implementations:

   org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp (default)
        Uses Java's built-in regular expression package

   org.apache.tools.ant.util.regexp.JakartaOroRegexp
        Requires  the jakarta-oro package

   org.apache.tools.ant.util.regexp.JakartaRegexpRegexp
        Requires the jakarta-regexp package

 Usage:

   Call Syntax:

     <replaceregexp file="file"
                    match="pattern"
                    replace="pattern"
                    flags="options"?
                    byline="true|false"?
                    failOnError="true|false"? >
       regexp?
       substitution?
       fileset*
     </replaceregexp>

    NOTE: You must have either the file attribute specified, or at least one fileset subelement
    to operation on.  You may not have the file attribute specified if you nest fileset elements
    inside this task.  Also, you cannot specify both match and a regular expression subelement at
    the same time, nor can you specify the replace attribute and the substitution subelement at
    the same time.

   Attributes:

     file    --> A single file to operation on (mutually exclusive
                    with the fileset subelements)
     match   --> The Regular expression to match
     replace --> The Expression replacement string
     flags   --> The options to give to the replacement
                 g = Substitute all occurrences. default is to replace only the first one
                 i = Case insensitive match

     byline  --> Should this file be processed a single line at a time (default is false)
                 "true" indicates to perform replacement on a line by line basis
                 "false" indicates to perform replacement on the whole file at once.

     failOnError --> Should this task fail if an error occurs (default is false)
                 "true" indicates that this task should fail if an error occurs
                 "false" indicates that this task should continue if an error occurs

  Example:

     The following call could be used to replace an old property name in a ".properties"
     file with a new name.  In the replace attribute, you can refer to any part of the
     match expression in parenthesis using backslash followed by a number like '\1'.

     <replaceregexp file="test.properties"
                    match="MyProperty=(.*)"
                    replace="NewProperty=\1"
                    byline="true" />