Ant propertyregex behaving strangely

I have the following:

<propertyregex property="myProp" input="${someInput}"
               regexp="(.*)" 
               replace="-f -d '\1'"
               override="true"/>

The intention of the propertyregex is to take the value of someInput and put it within single qoutes and prepend it with the -f and -d flags. If I set someInput to myString, the result that I expect would be:

-f -d 'myString'

but i get:

-f -d 'myString'-f -d ''

Can anyone explain where the trailing -f -d '' comes from?

Answers


The regex matches twice. Once it matches the entire string, and then it matches the empty string at the end of the string (since the asterisk allows zero-length matches).

Use

<propertyregex property="myProp" input="${someInput}"
               regexp="^.*" 
               replace="-f -d '\0'"
               override="true"/>

(\0 contains the entire match, so you also don't need the capturing parentheses).

See also this question.


Need Your Help

What's the best way to mix Spring MVC and CDI/JEE6?

jboss java-ee-6 glassfish-3 cdi

I'm not a fan of JSF. Spring MVC makes a lot of sense to me and I've used it in the past.

How are member types implemented?

c++

I'm looking at this resource:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.