E.11 ReplaceRegexp

The ReplaceRegexp filter will perform a regexp find/replace on the input stream. For example, if you want to replace ANT with Phing (ignoring case) and you want to replace references to *.java with *.php:

<filterchain>
  <replaceregexp>
    <regexp pattern="ANT" replace="Phing" ignoreCase="true"/>
    <regexp pattern="(\w+)\.java" replace="\1.php"/>
  </replaceregexp>
</filterchain>

Or, replace all Windows line-endings with Unix line-endings:

<filterchain>
  <replaceregexp>
    <regexp pattern="\r(\n)" replace="\1"/>
  </replaceregexp>
</filterchain>

E.11.1 Nested tags

The ReplaceRegExp filter must contain one or more regexp tags. These must have pattern and replace attributes. The full list of supported attributes is as following:

Table E.11:  Attributes for the <regexp> tag

NameTypeDescriptionDefaultRequired
patternStringRegular expression used as needle. Phing relies on Perl-compatible regular expressions. n/aYes
replaceStringReplacement string.n/aYes
ignoreCaseBooleanWhether search is case-insensitive.falseNo
multilineBooleanWhether regular expression is applied in multi-line mode.falseNo
modifiersStringRaw regular expression modifiers. You can pass several modifiers as single string, and use raw modifiers with ignoreCase and multiline attributes. In case of conflict, value specified by dedicated attribute takes precedence.''No

The previous example (using modifiers attribute this time):

<filterchain>
  <replaceregexp>
    <regexp pattern="ANT" replace="Phing" modifiers="i"/>
    <regexp pattern="(\w+)\.java" replace="\1.php"/>
  </replaceregexp>
</filterchain>