如何在 VBScript 中通过过滤器查找字符串?
How to find string by filter in VBScript?
我这里有问题:
我有这样的文字
a lot of html tags
MPI-START
Hello world!
Hello world 2!
MPI-END
a lot of html tags again
而且我需要以某种方式在 MPI-START 和 MPI-END 之间获取文本
它可以包含很多行和文本,所以我需要全部获取它们
我试图搜索但没有任何内容
有什么想法吗?
也对不起我的英语,我来自俄罗斯
UPD:我需要的文本包含在 < p data-placeholder="Your story...">TEXT</ p>
好的,我找到答案了
不完美但有效
Dim strid, outstr
strid = "many hell tags MPI-START" & vbNewLine & "Hello World!" & vbNewLine & "Hello World 2 !" & vbNewLine & "MPI-END there too"
outstr = Split (strid, "MPI-START")(1)
outstr = Split (outstr, "MPI-END")(0)
MsgBox outstr
这是另一个在 vbscript 中使用 RegEx
来提取两个分隔符之间的数据的方法:
Option Explicit
Dim Full_String,First_Delimiter,Second_Delimiter,Extracted_Data
Full_String = "a lot of html tags" & vbNewLine &_
"< p data-placeholder=""Your story..."">" & vbNewLine &_
"Hello world!" & vbNewLine &_
"Hello world 2!" & vbNewLine &_
"</ p>" & vbNewLine &_
"a lot of html tags again"
wscript.echo Full_String
First_Delimiter = "< p data-placeholder=""Your story..."">"
Second_Delimiter = "</ p>"
Extracted_Data = ExtractData(Full_String,First_Delimiter,Second_Delimiter)
wscript.echo Extracted_Data
'------------------------------------------------------------------------------------------------
Function ExtractData(Full_String,Start_Delim,End_Delim)
Dim r,Matches,Data
Set r=new regexp
r.pattern = "(?:^|(?:\r\n))(:?"& Start_Delim &"\r\n)([\s\S]*?)(?:\r\n)(?:"& End_Delim &")"
Set Matches = r.Execute(Full_String)
If Matches.Count > 0 Then Data = Matches(0).SubMatches(1)
ExtractData = Data
End Function
'------------------------------------------------------------------------------------------------
我这里有问题: 我有这样的文字
a lot of html tags
MPI-START
Hello world!
Hello world 2!
MPI-END
a lot of html tags again
而且我需要以某种方式在 MPI-START 和 MPI-END 之间获取文本
它可以包含很多行和文本,所以我需要全部获取它们
我试图搜索但没有任何内容
有什么想法吗?
也对不起我的英语,我来自俄罗斯
UPD:我需要的文本包含在 < p data-placeholder="Your story...">TEXT</ p>
好的,我找到答案了
不完美但有效
Dim strid, outstr
strid = "many hell tags MPI-START" & vbNewLine & "Hello World!" & vbNewLine & "Hello World 2 !" & vbNewLine & "MPI-END there too"
outstr = Split (strid, "MPI-START")(1)
outstr = Split (outstr, "MPI-END")(0)
MsgBox outstr
这是另一个在 vbscript 中使用 RegEx
来提取两个分隔符之间的数据的方法:
Option Explicit
Dim Full_String,First_Delimiter,Second_Delimiter,Extracted_Data
Full_String = "a lot of html tags" & vbNewLine &_
"< p data-placeholder=""Your story..."">" & vbNewLine &_
"Hello world!" & vbNewLine &_
"Hello world 2!" & vbNewLine &_
"</ p>" & vbNewLine &_
"a lot of html tags again"
wscript.echo Full_String
First_Delimiter = "< p data-placeholder=""Your story..."">"
Second_Delimiter = "</ p>"
Extracted_Data = ExtractData(Full_String,First_Delimiter,Second_Delimiter)
wscript.echo Extracted_Data
'------------------------------------------------------------------------------------------------
Function ExtractData(Full_String,Start_Delim,End_Delim)
Dim r,Matches,Data
Set r=new regexp
r.pattern = "(?:^|(?:\r\n))(:?"& Start_Delim &"\r\n)([\s\S]*?)(?:\r\n)(?:"& End_Delim &")"
Set Matches = r.Execute(Full_String)
If Matches.Count > 0 Then Data = Matches(0).SubMatches(1)
ExtractData = Data
End Function
'------------------------------------------------------------------------------------------------