當前位置:成語大全網 - 新華字典 - vba中用正則表達式提取數值給數組,求表達式?

vba中用正則表達式提取數值給數組,求表達式?

VBA Code(假設在 Excel 的活動工作表的 A1 單元格中存儲著上述 Json 字符串):

Option?Explicit

Sub?ExtractJsonData()

Dim?objRegExp?As?Object

Dim?objMatch?As?Object

Dim?objMatches?As?Object

Set?objRegExp?=?CreateObject("VBScript.RegExp")

With?objRegExp

.IgnoreCase?=?True

.Global?=?True

.Pattern?=?"""issue"":""(\d+?)"",""opennum"":""(.*?)"""

If?.Test([A1])?Then

Set?objMatches?=?.Execute([A1])

For?Each?objMatch?In?objMatches

Debug.Print?objMatch.SubMatches(0);?objMatch.SubMatches(1)

Next

End?If

End?With

End?Sub

運行結果:

表達式就是代碼中的 Pattern 屬性值