我需要使用NAnt来更新.js文件中的一个特定行.该行将是这样的:
global.ServerPath = 'http://server-path/';
Run Code Online (Sandbox Code Playgroud)
我需要一种方法来更新该行的"服务器路径"部分与目标服务器的部分.
ReplaceString并不好,因为当我更新它时,我不知道文件中的路径是什么.
有帮助吗?
提前致谢
The*_*man 12
如果string::replace不起作用就<regex>可以完成这项工作.就是这个:
<?xml version="1.0" encoding="utf-8" ?>
<project name="replace.line" default="replace">
<target name="replace" descripton="replaces a line">
<property
name="js.file"
value="C:\foo.js" />
<loadfile file="${js.file}" property="js.file.content" />
<regex
input="${js.file.content}"
pattern="(?'BEFORE'.*)global\.ServerPath\s*=\s*'[^']*';(?'AFTER'.*)" />
<echo
file="${js.file}"
message="${BEFORE}global.ServerPath = 'http://bla/';${AFTER}"
append="false" />
</target>
</project>
Run Code Online (Sandbox Code Playgroud)