代碼:
Function zhengze3(ze1 As String, ze2 As String, Rng1 As Range, Rng2 As Range)
Set regx1 = CreateObject("vbscript.regexp") '需要執行多個正則表達式時,只需要創建多個regx對象,然后分別執行正則即可
Set regx2 = CreateObject("vbscript.regexp")
With regx1
.Global = False
.Pattern = ze1 '寫正則表達式
Set m1 = .Execute(Rng1)
End With
With regx2
.Global = False
.Pattern = ze2 '寫正則表達式
Set m2 = .Execute(Rng2)
End With
zhengze3 = m2(0) & m1(0) 'm1和m2為列表,即使只有一個值,也需要以數組格式復制,如果省略括號的0,則報錯
End Function