想处理数据成图片里的样子,正则表达式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
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
解决方案 »
- 请推荐好用的工控仪表
- 急死了,编译dll文件时提示“未发现可创建的公共类部件”,编译不了,什么原因阿?Vb里用form能显示
- 在水晶报表中怎样把*.gif插入到报表中?向上帝保证绝对给分
- VSFLEXGRID的中文输入的问题,解决问题马上给分.
- winsock 的sendcomplete 事件 在线等待 3q
- 让数据库中一表的ID字段自动加1
- 问二个简单问题
- 编一个动态报表时......有一问题?SOS!!!SOS!!!
- 谁帮我解答一个非常简单的SQL问题,轻松赚30,我最后的分分哪。
- 为什么每次用WebBrowser_NewWindow2新打开的网页都是一个小窗口。怎么能改变新打开的WebBrowser的尺寸大小
- VB和access开发系统
- 求用vb做一个电影院选座系统
\w能不能匹配汉字要视你的操作系统和你的应用环境而定;
可能是EXCEL VBA中 \w 不能匹配中文的原因;