正则表达式的用法?

micool 2008-07-14 10:46:18
Dim objRegExp As RegExp
Dim objMatch As Match
Dim colMatches As MatchCollection
Dim RetStr As String

'' Create a regular expression object.
Set objRegExp = New RegExp

''Set the pattern by using the Pattern property.
objRegExp.Pattern = "<TD\swidth=""50%""><img\ssrc="".*?""\salign=""absmiddle"">\s<A\shref=""(.*?)""\starget=""_blank""><B>(.*?)</B></A></TD>"

'' Set Case Insensitivity.
objRegExp.IgnoreCase = True

''Set global applicability.
objRegExp.Global = True

''Test whether the String can be compared.
If (objRegExp.test(Text2.Text) = True) Then

''Get the matches.
Set colMatches = objRegExp.Execute(Text2.Text) '' Execute search.

For Each objMatch In colMatches '' Iterate Matches collection.
RetStr = RetStr & "Match found at position "
RetStr = RetStr & objMatch.FirstIndex & ". Match Value is ''"
RetStr = RetStr & objMatch.Value & "''." & vbCrLf
Next
Else
RetStr = "String Matching Failed"
End If
Text5.Text = RetStr

上面那段代码通过自己写的正则表达式 获取的是整个 连html标记在内的字符串
我要获取的是 objRegExp.Pattern = "<TD\swidth=""50%""><img\ssrc="".*?""\salign=""absmiddle"">\s<A\shref=""(.*?)""\starget=""_blank""><B>(.*?)</B></A></TD>"

中(.?)的内容 怎么写 ???
...全文
53 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
micool 2008-07-14
  • 打赏
  • 举报
回复
我已经知道答案了 。。。。
set MyReg = New RegExp
MyReg.IgnoreCase = true
MyReg.Global = true

MyReg.Pattern = " <a href= " "(.+?) " " title= " "(.*?) " "> .+? </a> "
set myMatches = MyReg.Execute(filecontent)

href = MyReg.Replace(myMatches(0), "$1 ")
title = MyReg.Replace(myMatches(0), "$2 ")

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧