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>
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
Name | Type | Description | Default | Required |
---|---|---|---|---|
pattern | String | Regular expression used as needle. Phing relies on Perl-compatible regular expressions. | n/a | Yes |
replace | String | Replacement string. | n/a | Yes |
ignoreCase | Boolean | Whether search is case-insensitive. | false | No |
multiline | Boolean | Whether regular expression is applied in multi-line mode. | false | No |
modifiers | String | Raw 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>