-
excel正则表达式提取
自定义函数-正则表达式:
Function TQ(rng, types As String) As String
Dim obj As Object
Set obj = CreateObject(“VBSCRIPT.REGEXP”)
With obj
.Global = True
Select Case types
Case Is = “-hz” '去汉字
.Pattern = “[一-﨩]”
Case Is = “-zm” '去字母
.Pattern = “[a-zA-Z]”
Case Is = “-sz” '去数字
.Pattern = “[0-9.]”
Case Is = “+hz” '取汉字
.Pattern = “[^一-﨩]”
Case Is = “+zm” '取字母
.Pattern = “[^a-zA-Z]”
Case Is = “+sz” '取数字
.Pattern = “[^0-9.]”
End Select
TQ = .Replace(rng, “”)
End
WithEnd Function
Function TQ(rng, types As String) As String
Dim obj As Object
Set obj = CreateObject(“VBSCRIPT.REGEXP”)
With obj
.Global = True
Select Case types
Case Is = “-hz” '去汉字
.Pattern = “[一-﨩]”
Case Is = “-zm” '去字母
.Pattern = “[a-zA-Z]”
Case Is = “-sz” '去数字
.Pattern = “[0-9.]”
Case Is = “+hz” '取汉字
.Pattern = “[^一-﨩]”
Case Is = “+zm” '取字母
.Pattern = “[^a-zA-Z]”
Case Is = “+sz” '取数字
.Pattern = “[^0-9.]”
End Select
TQ = .Replace(rng, “”)
End
WithEnd Function