Function GetChar(strChar As String, varType As Variant) '取值函数
Dim objRegExp As Object
Dim objMatch As Object
Dim strPattern As String
Dim arr
Set objRegExp = CreateObject("vbscript.regexp")
varType = LCase(varType)
Select Case varType
Case 1, "number"
strPattern = "-?\d+(\.\d+)?"
Case 2, "english"
strPattern = "[a-z]+"
Case 3, "chinese"
strPattern = "[\u4e00-\u9fa5]+"
End Select
With objRegExp
.Global = False '匹配到结果就停止
.IgnoreCase = True '忽略大小写
.Pattern = strPattern '匹配数字字母括号
Set objMatch = .Execute(strChar)
End With
If objMatch.Count = 0 Then
GetChar = ""
Exit Function
End If
ReDim arr(0 To objMatch.Count - 1)
For Each cell In objMatch
arr(i) = objMatch(i)
i = i + 1
Next
GetChar = arr
Set objRegExp = Nothing
Set objMatch = Nothing
End Function