|
TextReplace老版本就对 引号等提供了转义字符。 #q替换引号就能替换了。
最新版提供了第3个参数 TextReplace str1 str2 正则修饰符
"" , i 忽略大小写, g 全局匹配, m 多行匹配
http://www.w3school.com.cn/jsref/jsref_obj_regexp.asp
js的.*或者.+在匹配的时候把换行符的\r也会匹配,所以整行替换时,可能需要注意下。
具体例子在 lib\macros\tests\_Test_TextReplace.bat中有。
- echo Replace all "//EXP_"
- copy /y tests\Pecmd.ini tests\tmp\Pecmd.ini
- call TextReplace tests\tmp\Pecmd.ini #//EXP_ "" g
- echo Replace with escape mark
- call TextReplace tests\tmp\PecmdAdmin.ini "DefaultPassword=#q#q" "DefaultDomainName"
- echo Replace with escape mark
- call TextReplace tests\tmp\PecmdAdmin.ini "REGI HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword=#q#q" "REGI HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName"
- pause
- echo Replace all "Default" to "Admin"
- call TextReplace tests\tmp\PecmdAdmin.ini "Default" "Admin" g
- pause
- echo Replace *userinit.exe,* line to empty line
- call TextReplace tests\tmp\PecmdAdmin.ini "^.+userinit.exe,.+$" "#r" m
- pause
- echo Replace *userinit.exe,* line to empty line
- call TextReplace tests\tmp\PecmdAdmin.ini ".*userinit.exe,[^\r]*" "" ""
- pause
- echo *Remove* *userinit.exe,* line
- call TextReplace tests\tmp\PecmdAdmin.ini ".*userinit.exe,.*#r#n" "" ""
- pause
- echo Replace all _SUB XXXX to _FUNC XXXX()
- call TextReplace tests\tmp\PecmdAdmin.ini "^_SUB\s([^\r]+)$" "_FUNC $1()" mg
- pause
复制代码 |
|