見例子。
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Sub ReplaceCmd
'Remove^from quoting command line. Quote, ampersand and brackets
Pttn = Replace(Arg(2), "^(", "(")
Pttn = Replace(Pttn, "^)", ")")
Pttn = Replace(Pttn, "^&", "&")
Pttn = Replace(Pttn, "^""", """")
Set regEx1 = New RegExp
If Instr(LCase(Arg(1)), "i") > 0 then
regEx1.IgnoreCase = True
Else
regEx1.IgnoreCase = False
End If
regEx1.Global = False
regEx1.Pattern = Pttn
Do Until Inp.AtEndOfStream
Line=Inp.readline
Line = RegEx1.Replace(Line, Arg(3))
outp.writeline Line
Loop
End Sub
要使用cscript scriptname <infile >outfile
更換
filter replace {i|n} expression replace
filter repl {i|n} expression replace
發現和使用正則表達式替換文本。
也用於從文件中提取子字符串。
表達式中的&符號和括號內必須使用脫字符。不要逃脫插入。使用十六進制代碼\ x22作爲引號。
SearchOptions
我 - 忽略大小寫 N - 無 表達
正則表達式參考
更換
替換的文本。使用$ 1,$ 2,$ ...,$ N來替換字符串中指定的子場比賽
例
filter replace i "=" "No equal sign" < "%systemroot%\win.ini"
這種搜索方括號內的文字和替換貓行後跟內的文本括號
Filter replace i "^\[^(.*^)\]" "cat$1" < %windir%\win.ini
這將搜索任何文本並從第11個字符打印到行尾。
Filter replace i "^.{10}^(.*^)$" "$1" < %windir%\win.ini
此搜索的CSV文件,並打印所述第二和第四場
Filter replace i "^.+,^(.+^),.+,^(.+^)$" "$1,$2" < csv.txt
你的問題是什麼? –