### 新建一个空白表格文件 ### ALT+F11 进入VB编辑器 ![](/usr/uploads/2021/07/1565336351.png) ### 插入模块插入模块 ![](/usr/uploads/2021/07/272791998.png) ### 工具-引用-勾选正则表达式 Microsoft VBScript Regular Express 5.5 ![](/usr/uploads/2021/07/1659217641.png) 复制代码 ```vb Option Explicit Public Function re_sub(sText As String, pattern As String, repl As String) Dim oRegExp As Object Set oRegExp = CreateObject("vbscript.regexp") With oRegExp .Global = True 'True表示匹配所有, False表示仅匹配第一个符合项 .IgnoreCase = False '区分大小写 .pattern = pattern re_sub = .Replace(sText, repl) End With End Function Public Function re_find(sText As String, pattern As String) Dim oRegExp As Object, match As Object, matches As Object Set oRegExp = CreateObject("vbscript.regexp") With oRegExp .Global = True 'True表示匹配所有, False表示仅匹配第一个符合项 .IgnoreCase = True '不区分大小写 .pattern = pattern Set matches = .Execute(sText) End With Dim d As Object Set d = CreateObject("Scripting.Dictionary") For Each match In matches d.Add match, Null Next re_find = d.keys End Function Public Function re_extract(sText As String, pattern As String) Dim oRegExp As Object, match As Object, matches As Object, i As Integer Set oRegExp = CreateObject("vbscript.regexp") With oRegExp .Global = True 'True表示匹配所有, False表示仅匹配第一个符合项 .IgnoreCase = True '不区分大小写 .pattern = pattern Set matches = .Execute(sText)(0).submatches End With Dim d As Object Set d = CreateObject("Scripting.Dictionary") For i = 0 To matches.Count - 1 d.Add matches(i), Null Next re_extract = d.keys End Function ``` ### 保存为启用宏的模板文件 ![](/usr/uploads/2021/07/982277121.png) ### 函数命令 re_extract re_find re_sub WMI Scripting HTML 当前访问者IP地址及地址归属: Last modification:July 12th, 2021 at 04:17 pm © 允许规范转载 Support 如果觉得我的文章对你有用,请随意赞赏 ×Close Appreciate the author Sweeping payments