基于YYYY-WW的date的正则expression式

我有以下[有效]正则expression式,我想要放入VBA应用程序:

(?<year>(\d{2}){0,2}[-\/]?)(?<week>(\d{2})) 

我不断收到错误5017.对象'IRegExp2'不支持'Execute'方法。

但是,如果我放弃命名的捕获并插入:

 ((\d{2}){0,2}[-\/]?)((\d{2})) 

我正确地认为正则expression式的“vbscript”酸味不支持命名组?

是否有另一个标准(Windows)库,我可以在VBA中引用,以获得更好的正则expression式分析器?

我很喜欢使用C#,因为它立即工作,并拉出我的团队,但我被限制为VBA,因为我的整个应用程序插件是在MS Office中。

YYYY-WW (1900-01和2999-52之间)兼容VBA的正则expression式是:

 ([1-2][0-9])([0-9][0-9])[-\/](0[1-9]|[1-4][0-9]|5[0-2]) 

这将排除第53至99周。

为了获得世纪,年份,星期,使用SubMatches集合获取不同的捕获组。

 Option Explicit Sub TestYYYYWWRegex() Dim objRegex As New RegExp Dim objMatches As MatchCollection Dim varTests As Variant Dim varTest As Variant Dim strMessage As String objRegex.Pattern = "([1-2][0-9])([0-9][0-9])[-\/](0[1-9]|[1-4][0-9]|5[0-2])" varTests = Array("2017-13", "1975-09", "2016-63", "zz78-0g", "1978-00", "1234-56", "1234-01", "YYYY-WW") For Each varTest In varTests Set objMatches = objRegex.Execute(CStr(varTest)) If objMatches.Count > 0 Then With objMatches strMessage = "Matched: " & CStr(varTest) strMessage = strMessage & " C: " & .Item(0).SubMatches(0) strMessage = strMessage & " Y: " & .Item(0).SubMatches(1) strMessage = strMessage & " W: " & .Item(0).SubMatches(2) End With Else strMessage = "No match for: " & CStr(varTest) End If 'check test case Debug.Print strMessage Next varTest End Sub 

testing用例:

 Matched: 2017-13 C: 20 Y: 17 W: 13 Matched: 1975-09 C: 19 Y: 75 W: 09 No match for: 2016-63 No match for: zz78-0g No match for: 1978-00 No match for: 1234-56 Matched: 1234-01 C: 12 Y: 34 W: 01 No match for: YYYY-WW