How to use string value as a part of regular expression in groovy?
I’am writing ant build script using groovy, here is some snapshot:
<target name="groovy.showProperties">
<groovy>
class ShowProperties extends org.apache.tools.ant.Task {
String nameMatch;
public void execute() {
project.properties.each
{prop ->
//I don't know how to obtain nameMatch value
if(prop.key ==~ /.*nameMatch.*/)
{
println prop;
}
};
}
}
project.addTaskDefinition('dump', ShowProperties)
</groovy>
<echo>example:</echo>
<dump nameMatch="lang"/>
</target>
It should be:
Does that not work?
Edit:
Taking your example task, and wrapping it in a valid
build.xmllike so:I can then do:
And I get the output:
No parse errors or anything… What version of Groovy are you using?