I’m trying to to a trim to some values using replaceregexp. Everything looks great when I try it in software like EditPad Pro.
Here’s a sample of what I want to accomplish:
mf.version.impl = 2.01.00
mf.version.spec= 2.01.00
Notice the extra spaces after the last digit.
Then I’m using this pattern:
[0-9]+.[0-9]+.[0-9]+[ ]*
But it doesn’t work in Netbeans.
Here’s my ant command for it:
<!--If postfix is empty, remove the empty space-->
<replaceregexp file="../Xinco/nbproject/project.properties"
match="mf.version.spec?=?[0-9]+.[0-9]+.[0-9]+[ ]*"
replace="mf.version.spec = ${version_high}.${version_mid}.${version_low}"
byline="false"/>
<replaceregexp file="../Xinco/nbproject/project.properties"
match="mf.version.impl?=?[0-9]+.[0-9]+.[0-9]+[ ]*"
replace="mf.version.impl = ${version_high}.${version_mid}.${version_low}"
byline="true"/>
${version_high}.${version_mid}.${version_low} are variables already defined that correspond to 2.01.00 respectively.
It results in
mf.version.impl = 2.01.00
mf.version.spec = 2.01.00
Notice one extra space after the last digit.
I did debug the ant calls and it seems like the above command is not executing like a match didn’t occur.
Any idea?
Since you don’t care about the value, you don’t have to match it explicitly. Try:
Meaning:
^– start of the line (on multiline mode)mf\.version\.impl– the string "mf.version.impl" literally, with the dots escaped.\s*– zero or more spaces.*– anything else (we can ignore the version, since you change it with a constant), all the way through to the…$– end of the lineBonus track:
Looking at the specs, it looks like you can catch both lines with a single regex (not sure it works though):
and the replace rule:
This will replace
\1with the value it captured before, so again, you only need a single rule. (for trivia, usually$1is used in replaces, but not here)