我正在尝试使用 Ant 替换 xml 中的值。
我的 xml 文件:
<session-config>
<session-timeout>60</session-timeout>
</session-config>
Run Code Online (Sandbox Code Playgroud)
我想更换60为20
并在 ant 任务中用于以下正则表达式replaceregexp:
(?<=session-timeout>)[\S\s]*?(?=</session-timeout)
<target name="step1">
<replaceregexp file="WEB-INF/web.xml"
byline="true"
match="((?<=session-timeout\>)[\S\s]*?(?=\<\/session-timeout))"
replace='20'/>
</target>
Run Code Online (Sandbox Code Playgroud)
但是在执行后得到了来自ant的致命错误:
[Fatal Error] The value of attribute "match" associated with an element type "replaceregexp"
must not contain the '<' character.
Run Code Online (Sandbox Code Playgroud)
请指教,如何更改我的正则表达式,或者这个问题有另一种解决方案吗?谢谢。
<和>字符必须分别使用<和进行“转义” >:
<replaceregexp file="WEB-INF/web.xml"
byline="true"
match="((?<=session-timeout\>)[\S\s]*?(?=\<\/session-timeout))"
replace='20'/>
Run Code Online (Sandbox Code Playgroud)