但是在正則運算式測驗中能通過,相同陳述句在WORD中用VBA就出錯,請問是什么原因?是代碼不同嗎?謝謝了

Sub 測驗()
Dim myString As Variant, mt, mh, isr
Application.ScreenUpdating = False
Set reg = CreateObject("vbscript.regexp")
myString = "我人民幣大寫:123656.00。小寫:123654.03 中介人民幣大寫:800.36公司日豐人民幣大寫:36659.32.日韓地晶上 "
With reg
Pattern = "(?<=人民幣大寫:)\d+[\d.]{1,3}"
'.Pattern = "\d+(\.[0-9]{1,2})"
.Global = True
.IgnoreCase = False
.MultiLine = True
Set mh = .Execute(myString)
End With
For i = 0 To mh.Count - 1
isr = isr & mh(i).SubMatches(0) & " "
Next
ActiveDocument.Content.Text = isr
Application.ScreenUpdating = True
End Sub
.Pattern = "\d+(\.[0-9]{1,2})"
這句也是,在測驗時能讀取數字,在VBA中只有.00 .03等,沒有前面的整數,但測驗網站測驗時能正常讀出資料
uj5u.com熱心網友回復:
Sub 測驗()
Dim myString As Variant, mt, mh, isr
Application.ScreenUpdating = False
Set reg = CreateObject("vbscript.regexp")
myString = "我人民幣大寫:123656.00。小寫:123654.03 中介人民幣大寫:800.36公司日豐人民幣大寫:36659.32.日韓地晶上 "
With reg
.Pattern = "(人民幣大寫:)(\d+\.[0-9]{1,3})"
.Global = True
.IgnoreCase = False
.MultiLine = True
Set mh = .Execute(myString)
End With
For i = 0 To mh.Count - 1
isr = isr & mh(i).SubMatches(1) & " "
Next
ActiveDocument.Content.Text = isr
Application.ScreenUpdating = True
End Sub
uj5u.com熱心網友回復:
那是因為正則運算式決議器的問題。你測驗的那個工具的決議器比較先進,能解釋反向匹配,而vb或者vba,vbs之類的比較老,只支持基本的正則特性,不支持<=反向匹配這些新特性。你不就是要獲取大寫后面的東西么,其實很簡單,直接寫:大寫:\d+[\d.]{1,3} 就好了啊。
以下也都可以:
大寫:[\d\.]+
(?:大寫:)[\d\.]+
(?:大寫:)([\d\.]+)
(?:大寫:)([\d\.]+)\.?
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/270066.html
標籤:VBA
上一篇:尋找問題和更簡潔的VBA
下一篇:MFC處理事件的順序
