[問題] VBA的regex

作者: gecer (gecer)   2014-07-05 08:53:49
語言 VBA excel 2007 windows XP
code as follow
********************************************************************
Dim myRegExp As Object
Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "^(\d+\s+[0-7]\s+\d+(uA|mV))"
Dim s As String: s = "6532 0 70mV "
Dim m As Object
Set m = myRegExp.Execute(s)
**********************************************************************
I want to match "6532 0 70mV" or "6532 0 70uA"
but when s is "6532 0 70uA" the m contains only one item,which is
"6532 0 70uA" http://i.imgur.com/PFQNfZ9.png ,but when
s="6532 0 70mV" it contains 2 items "6532 0 70mV" and "mV"
http://i.imgur.com/Pg2gqNu.png,
I don't know why the later case contains 2
作者: LPH66 (-6.2598534e+18f)   2014-07-05 19:54:00
((uA)|(mV)) 這樣試試?
作者: lin1987www (林奕忠)   2014-07-07 09:22:00
你累了 Q_Q 仔細看其實是你看錯了! Match的數量都是1第一張圖是你看Match(m)的數量,第二張圖是你PatternMatch的數量

Links booklink

Contact Us: admin [ a t ] ucptt.com