'测试:将“abc@@eee”中的@@提取出来
Sub test()
MsgBox GetValueByRegex("abc@@eee", "abc(.*?)eee")
End Sub
Function GetValueByRegex(ByVal OrgStr As String, ByVal PatternStr As String)
Set re = CreateObject("VBScript.RegExp")
re.Pattern = PatternStr
re.Global = True
re.IgnoreCase = False
Set matchs = re.Execute(OrgStr)
If matchs.Count > 0 Then
GetValueByRegex = matchs(0).submatches(0)
Else
GetValueByRegex = ""
End If
End Function

本文介绍了一种使用Visual Basic Scripting(VBS)中的正则表达式从特定格式字符串中提取所需部分的方法。通过一个具体示例,演示了如何定义正则表达式模式并应用到字符串上,从而实现精准的数据抽取。
&spm=1001.2101.3001.5002&articleId=105500100&d=1&t=3&u=c3bc67ede0bc4f178b36ddaafa96e773)
2250

被折叠的 条评论
为什么被折叠?



