|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
周末无事,写个自定义函数 :Function resultString(ByVal s As String) As String
正则表达式: (^|\D)(4\d{9}|\d{6}-\d{3}-\d{4})(?!\d)- Function resultString(ByVal s As String) As String
- Set D = CreateObject("htmlfile"): Set js = D.parentWindow
- js.execScript "var re=/./.compile(/(^|\D)(4\d{9}|\d{6}-\d{3}-\d{4})(?!\d)/g);"
- js.execScript "var a=[];while(m=re.exec('" & s & "'))a.push(m[2]);"
- resultString = js.eval("a?a.join('|'):'';")
- End Function
- Sub main()
- Dim arr, s
- arr = Array("Without demand, using in 900070-130-2405", "ECO design change product PN from 900060-130-0803 to 900060-130-0804", "Without demand, using in 4030940003", "EOL, using in F7 SCU P/N: 4030672003,900060-130-0803", "EOL, using in F7 SCU P/N: 4030672003,SCU P/N:4030672006")
- For Each s In arr
- MsgBox resultString(s)
- Next
- End Sub
复制代码
|
|