replaceregexp修剪在Netbeans中无法正常工作
我正在尝试使用replaceregexp修剪一些值。当我在像EditPad Pro这样的软件中试用时,一切看起来都很棒 以下是我想要完成的一个示例:replaceregexp修剪在Netbeans中无法正常工作,regex,ant,Regex,Ant,我正在尝试使用replaceregexp修剪一些值。当我在像EditPad Pro这样的软件中试用时,一切看起来都很棒 以下是我想要完成的一个示例: mf.version.impl = 2.01.00 mf.version.spec= 2.01.00 注意最后一个数字后面的多余空格。 然后我使用这个模式: [0-9]+.[0-9]+.[0-9]+[ ]* 但它在Netbeans中不起作用 下面是我的ant命令: <!--If postfix is empty, remove t
mf.version.impl = 2.01.00
mf.version.spec= 2.01.00
注意最后一个数字后面的多余空格。
然后我使用这个模式:
[0-9]+.[0-9]+.[0-9]+[ ]*
但它在Netbeans中不起作用
下面是我的ant命令:
<!--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"/>
注意最后一个数字后面有一个额外的空格。
我调试了ant调用,看起来上面的命令没有执行,好像没有发生匹配
有什么想法吗?你可能应该逃离你的家庭,使用一个捕获组 e、 g.(例如Perl正则表达式)
因为您不关心该值,所以不必显式地匹配它。尝试:
^mf\.version\.impl\s*=.*$
意思是:
-行的开始(在多行模式下)^
-字符串“mf.version.impl”字面意思,带转义点mf\.version\.impl
-零个或多个空格\s*
-任何其他内容(我们可以忽略版本,因为您使用常量更改它),一直到*
-行尾$
replace="\1 = ${version_high}.${version_mid}.${version_low}"
这将用以前捕获的值替换
\1
,因此,您只需要一条规则。(对于琐事,通常在替换中使用$1
,但在这里不使用)对于其中一个,您应该避开点:\。
。这纯粹是出于偶然:)我对ant一无所知,但这毫无意义?
作用于它前面的一个字符,因此可以匹配mf.version.imp2c01d00
,并且不留空格。这对您有用吗^mf.version.impl\s*=.*$
?这只会检查线条的开头和结尾的匹配。我也注意到了这一点。已删除。无论如何,谢谢。你的建议奏效了!用^mf.version.impl\s*=.*$写一个答案,这样我就可以奖励它答案了!顺便说一句,你能解释一下这是怎么回事吗?
^mf\.version\.impl\s*=.*$
^(mf\.version\.(impl|spec))\s*=.*$
replace="\1 = ${version_high}.${version_mid}.${version_low}"