ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject New Task: Regular Expression Replace
Date Tue, 02 Jan 2001 14:00:48 GMT
Attached is the source for a task that performs a regular expression
substitution inline on a file or a set of files. 
The substitution pattern can contain references to subexpressions within the
find pattern, which makes it possible to use fragments of the original text
in the new text. 

The syntax and implementation borrows from the replace task, for example:

<rereplace file="${src}/index.html" find="f([ae])ll" replaceWith="b$$1ll" />

will replace all occurrences of "fall" or "fell" in index.html with "ball"
and "bell", respectively.

This implementation relies upon the jakarta-oro regular expression package
(see, although it is relatively simply to
modify the code to support alternative regular expression packages.

Documentation and some examples can be found in the attached archive.

I've seen a few requests for this functionality on the list, and I've found
this task to be useful, so I thought others might also.  In theory, this
could replace the replace task altogether, but I've packaged it as optional
since it depends upon the oro library.

(The archive also includes a support class that implements an arbitrary
nested element containing text, which may be independently useful.)


 Rod Waldhoff <>

View raw message