|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
以下为网页的部分内容:
...............>27</a>
<a href=?sortfd=%e6%b6%a8%e8%b7%8c%e5%b9%85&marketid=&hy=§ypeid=1&sortway=desc&scb=&stockcode=&page=28&mystock= target=_self>28</a>
<a href=?sortfd=%e6%b6%a8%e8%b7%8c%e5%b9%85&marketid=&hy=§ypeid=1&sortway=desc&scb=&stockcode=&page=29&mystock= target=_self>29</a>
<a href=?sortfd=%e6%b6%a8%e8%b7%8c%e5%b9%85&marketid=&hy=§ypeid=1&sortway=desc&scb=&stockcode=&page=2&mystock= target=_self>下一页</a>
</div><!--/93.421875--></div>
Private Sub CommandButton1_Click()
Dim str As String
Dim Regex As Object
Set Regex = CreateObject("vbscript.regexp")
With Regex
.Global = True '全局有效
.MultiLine = True '多行有效
.IgnoreCase = True '忽略大小写
End With
str = Cells(2, "B").Value '此为第1种字符串,运行正常
Regex.Pattern = Cells(3, "B").Value
Cells(4, "B") = Regex.Execute(str).Item(0)
Cells(5, "B") = Regex.Execute(str).Item(0).SubMatches(0)
Set Regex = Nothing '清空正则项目
End Sub
我用正则表达式(\d+)</a>\n<a[\s\S][^>]*?>下一页</a>获得如下部分内容:
29</a>
<a href=?sortfd=%e6%b6%a8%e8%b7%8c%e5%b9%85&marketid=&hy=§ypeid=1&sortway=desc&scb=&stockcode=&page=2&mystock= target=_self>下一页</a>
|
|