我试图使用以下表达式在我的Excel数据中找到文本模式.目标是在文本找到后删除它.
/.([0-9] + [] X [] [0-9] + []?DPI)./一世
救命!
我创建了一个用户定义函数来运行正则表达式搜索并在单元格中显示最终匹配.
=udfRegEx([Cell you want to find the expression],[Cell with the regular expression you want to use])
Run Code Online (Sandbox Code Playgroud)
您需要打开Visual Basic编辑器并将以下代码放入模块:
Function udfRegEx(CellLocation As Range, RegPattern As String)
Dim RegEx As Object, RegMatchCollection As Object, RegMatch As Object
Dim OutPutStr As String
Set RegEx = CreateObject("vbscript.regexp")
With RegEx
.Global = True
.Pattern = RegPattern
End With
OutPutStr = ""
Set RegMatchCollection = RegEx.Execute(CellLocation.Value)
For Each RegMatch In RegMatchCollection
OutPutStr = OutPutStr & RegMatch
Next
udfRegEx = OutPutStr
Set RegMatchCollection = Nothing
Set RegEx = Nothing
Set Myrange = Nothing
End Function
Run Code Online (Sandbox Code Playgroud)
另外,不要忘记添加Microsoft VBScript正则表达式5.5的参考