为了方便使用正则表达式,可自定义函数如下: Public Function searchk(ByVal pat As String, ByVal str As String, Optional ByVal group As Integer = 0) As String Set regexp = CreateObject("VBScript.regexp") With regexp .Global = True .IGNORECASE = False .Pattern = pat If .test(str) Then searchk = .Execute(str)(group) Else searchk = "" End If End With End Function 在Excel里直接当函数使用了,如要将 A1 A2 A3的苹果奶2392ml,重量540g,体重147斤重 数据中的带单位数值提取出来,可以在B1单元格中输入=SEARCHk("\d+(ml|g|k|斤)",A1),往下拉即可出结果。 |
|