【发布时间】:2012-03-16 21:13:35
【问题描述】:
我正在尝试使用以下表达式在我的 Excel 数据中定位文本模式。目标是在找到文本后将其删除。
/.([0-9]+[]?x[]?[0-9]+[]?dpi)./i
救命!
【问题讨论】:
-
欢迎来到 Stack Overflow。建议您展示您迄今为止所做的尝试——具体问题往往会得到最多的关注。你能举个例子吗?
标签: excel-2007
我正在尝试使用以下表达式在我的 Excel 数据中定位文本模式。目标是在找到文本后将其删除。
/.([0-9]+[]?x[]?[0-9]+[]?dpi)./i
救命!
【问题讨论】:
标签: excel-2007
我创建了一个用户定义函数来运行正则表达式搜索并在单元格中显示最终匹配项。
=udfRegEx([Cell you want to find the expression],[Cell with the regular expression you want to use])
您需要打开 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
别忘了添加 Microsoft VBScript Regular Expressions 5.5 的参考
【讨论】:
您没有指定它,但我认为它使用的是 VBA 宏。我不认为您可以使用公式直接在工作表中进行正则表达式。
以下链接应该可以帮助您了解正则表达式和 VBA:
http://www.regular-expressions.info/vb.html
请务必添加正确的参考“Microsoft VBScript 正则表达式 5.5”
希望有帮助
【讨论】: