Regular Expression Replacement in an Ant Property

I’m quite a newbie in Ant, but I thought it would be straightforward to do a regular expression replacement in a string contained in a property; in my case, I had to replace Windows backslashes with Unix slashes… apparently, unless you use the propertyregex task from Ant Contrib, that is not supported out-of-the-box: you have to pass through a file!

This stackoverflow post shows a possible solution, and starting from that, I created a macrodef to make it easier

This macro takes the property value to process (property.to.process) and the property name where to store the result; it outputs the input value to a temporary file, reads it back with a regular expression replacement (which is supported for files) and store it in the specified property (the temporary file is then deleted).

Here’s an example of use

 

6 thoughts on “Regular Expression Replacement in an Ant Property

    1. Lorenzo Bettini Post author

      Philippe, try what? Probably special chars have been removed when you posted your comment?

      Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.