如果文本字符串包含某些单词,则将这些单词包装在 span 标记中
If text string contains certain words, wrap those words in a span tag
在此寻求一点帮助。我有一个像这样的文本字符串:
> ...And The World Laughs With You (feat Thom Yorke)
使用 vbscript
,如果文本字符串中包含 "(feat "
,我想将整个括号内的文本包装在一个 span 标记中。
所以,上面的例子看起来像:
> ...And The World Laughs With You <span>(feat Thom Yorke)</span>
希望这是有道理的,并提前感谢您的帮助!
干杯,
德鲁
查看示例。
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 作为引号。
搜索选项
i - 忽略大小写
n - none
表达式
正则表达式参考
替换
要替换的文本。使用 $1, $2, $..., $n 指定替换字符串中的子匹配项
例子
filter replace i "=" "No equal sign" < "%systemroot%\win.ini"
这将搜索方括号内的文本,并将该行替换为 cat 后跟括号内的文本
Filter replace i "^\[^(.*^)\]" "cat" < %windir%\win.ini
这将搜索任何文本并从第 11 个字符打印到行尾。
Filter replace i "^.{10}^(.*^)$" "" < %windir%\win.ini
这将搜索 CSV 文件并打印第二个和第四个字段
Filter replace i "^.+,^(.+^),.+,^(.+^)$" "," < csv.txt
试试这个逻辑。
dim str
str = "And The World Laughs With You (feat Thom Yorke)"
If INSTR(str,"(feat ") > -1 Then
str = REPLACE(str,"(feat ","<span>(feat ")
str = REPLACE(str,")",")</span>")
End If
Response.Write("Result:- " + str)
在此寻求一点帮助。我有一个像这样的文本字符串:
> ...And The World Laughs With You (feat Thom Yorke)
使用 vbscript
,如果文本字符串中包含 "(feat "
,我想将整个括号内的文本包装在一个 span 标记中。
所以,上面的例子看起来像:
> ...And The World Laughs With You <span>(feat Thom Yorke)</span>
希望这是有道理的,并提前感谢您的帮助!
干杯,
德鲁
查看示例。
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 作为引号。
搜索选项
i - 忽略大小写 n - none 表达式
正则表达式参考
替换
要替换的文本。使用 $1, $2, $..., $n 指定替换字符串中的子匹配项
例子
filter replace i "=" "No equal sign" < "%systemroot%\win.ini"
这将搜索方括号内的文本,并将该行替换为 cat 后跟括号内的文本
Filter replace i "^\[^(.*^)\]" "cat" < %windir%\win.ini
这将搜索任何文本并从第 11 个字符打印到行尾。
Filter replace i "^.{10}^(.*^)$" "" < %windir%\win.ini
这将搜索 CSV 文件并打印第二个和第四个字段
Filter replace i "^.+,^(.+^),.+,^(.+^)$" "," < csv.txt
试试这个逻辑。
dim str
str = "And The World Laughs With You (feat Thom Yorke)"
If INSTR(str,"(feat ") > -1 Then
str = REPLACE(str,"(feat ","<span>(feat ")
str = REPLACE(str,")",")</span>")
End If
Response.Write("Result:- " + str)