2
我正在努力驗證我想在Excel(VBA)中使用的正則表達式語法。該語法在網絡上的每個驗證器引擎中運行良好,但我無法在Excel中使用它。Excel中的表達式語法?
任何人都可以幫助我,我非常感謝。
表達:
^.+(?<!/)(?=/?[RP]\d)
數據來驗證:ABC12345/67/R1A
預期結果:ABC12345/67
我正在努力驗證我想在Excel(VBA)中使用的正則表達式語法。該語法在網絡上的每個驗證器引擎中運行良好,但我無法在Excel中使用它。Excel中的表達式語法?
任何人都可以幫助我,我非常感謝。
表達:
^.+(?<!/)(?=/?[RP]\d)
數據來驗證:ABC12345/67/R1A
預期結果:ABC12345/67
請檢查此正則表達式^.+(?<!/)(?=/?[RP]\d)
作爲其不給出預期的輸出。 它適用於^.+(?=/[RP]\d)
。以下是示例代碼。
Sub Main()
Dim stringToValidate As String
Dim stringResult As String
stringToValidate = "ABC12345/67/R1A"
stringResult = getData(stringToValidate)
End Sub
Function getData(ByVal str As String) As String
Dim objRegEx As Object
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.IgnoreCase = True
objRegEx.Global = True
objRegEx.Pattern = "^.+(?=/[RP]\d)"
Set allMatches = objRegEx.Execute(str)
For i = 0 To allMatches.Count - 1
result = result & allMatches.Item(i)
Next
getData = result
End Function
試試這個'^ +(?=/[RP] \ d)' – Santosh
很抱歉,但沒有奏效... – Johnny
退房[這](http://regexr.com?371tb) – Santosh