想处理数据成图片里的样子,正则表达式
myreg2.Pattern = "\s*(\S+)奖(\S+)”
myreg2.Pattern = "(\w+)奖(\w+)"
比如 出勤奖三等 销售奖二等
excel运行上面对下面错,下面的为空值,可是正则测试器里两个都是对的,这是为什么?
Sub demo3()
Worksheets(1).Activate
Dim myreg1 As Object, myreg2 As Object, mymatch1 As Object
Dim mymc, mymatch2 As Object, k, mymatches1, mymatches2, mydata, i, j
i = 6
Set myreg1 = CreateObject("vbscript.regexp")
myreg1.Global = True
myreg1.Pattern = "姓名:\s*(\S+)\s*获奖情况:([^;]+);"
Set myreg2 = CreateObject("vbscript.regexp")
myreg2.Global = True
myreg2.Pattern = "\s*(\S+)奖(\S+)"
'myreg2.Pattern = "(\w+)奖(\w+)"
mydata = Cells(1, 1).Value
Set mymatch1 = myreg1.Execute(mydata)
For Each mymatches1 In mymatch1
mymc = mymatches1.submatches(1)
Set mymatch2 = myreg2.Execute(mymc)
For Each mymatches2 In mymatch2
MsgBox mymatches2.submatches(0)
Next
Next