I can’t find the way to remove a space using ant. (I don’t mean trim, but removing from ~ to )
I want to make one project a little difference from another project.
For example:
I have below code.
.... doSomeThing;
//#removeStart
NotReleasedObject nro = new NotReleasedObject();
nro.doSomeThing();
//removeEnd#
....doAnyThing..
as you can see easily, I want to remove from //#removeStart to //removeEnd#. I’m not sure how much code will be written, but all code inside these 2 tags need to be gone.And there can be multiple //#removeStart ... //removeEnd# in one java file.
Here is my test replaceregexp code:
<replaceregexp flags="s" replace="" byline="false" encoding="utf-8">
<regexp pattern="//#removeStart.*//removeEnd#"/>
<fileset dir="${extern-source-path}"/>
</replaceregexp>
------ source for victim.
//#removeStart
space 1
//removeEnd#
something
//#removeStart
space 2
//removeEnd#
Now my code is not working properly.The flag -s works, but if one file has more than 1 match, then everything from space 1 to space 2 is gone. ( including something!)
What I actually want is space 1,2 gone, but something should be left as it is.
How can I fix it so that it replaces each occurrence 1 by 1 ?
Your explicit characters don’t match: your regex says
//##ExternRemovewhereas your actual text is either//##removeStartor//#removeStart. If that’s an actual regex, the explicit characters need to be exactly the same. Also.doesn’t match newlines, you’d need to include that specifically (e.g.[\s\S]*).Finally, you should make the matching non-greedy if you might have multiple pairs of this match (often this is by adding
?). Taken together, you’d probably want a regular expression like:That’s assuming you want to allow 1-2
#to start a line and that the phrase will always beremoveStart/removeEnd. Otherwise you could add options, e.g.again, this depends on the ant terminology for non-capturing matches.