如何使vb6的正则表达式匹配代码来提取域名 [英] How to make Regex match code for vb6 to extract domain names

查看:152
本文介绍了如何使vb6的正则表达式匹配代码来提取域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

如何使用vb6的正则表达式匹配代码来提取域名,但仅限于此类相关链接。例如,如果我写visual basic这个词,那么我的程序显示关于视觉基础这个词的相关链接,如http://www.vbforbegginers.com

http://www.vb.nethardturorials.info

http: //www.vb.netgodcity.us

http://www.vb.netfunnytutorials.com

但我失败了。我正在使用以下代码。



Dear to all,
How to make Regex match code for vb6 to extract domain names but only with related links like this.For example if i write the word "visual basic" then my program show me related links about the word "visual basic" such as http://www.vbforbegginers.com
http://www.vb.nethardturorials.info
http://www.vb.netgodcity.us
http://www.vb.netfunnytutorials.com
but i failed.I am using following code.

Dim  dsource  As String
   Dim result
   dsource = "http://www.google.lt/search?num=100&q=" & Text2.Text
   Set regweb = New RegExp            ' Create a regular expression.
   regweb.Pattern = "http://\b\w+\s\\(net|com|us|org|ru|lt|co.uk|tr|info(ftp|telnet)\*$"
   regweb.IgnoreCase = True         ' Set case insensitivity.
   regweb.Global = True           ' Set global applicability.
           result = Inet1.OpenURL(dsource)

   Set Matches2 = regweb.Execute(dsource)

   For Each Match2 In Matches2
   sweb = Match2
   Debug.Print result & dweb.Exists(result)
   If dweb.Exists(result) = False Then
   dweb.Add (result), 1
   List2.AddItem result
   Beep
   End If
   Next



请检查并帮助我。谢谢


Please check and help me.Thanks

推荐答案


regweb.IgnoreCase = True ' 设置不区分大小写。
regweb。全局 = True ' 设置全局适用性。
result = Inet1.OpenURL(dsource)

设置 Matches2 = re gweb.Execute(dsource)

对于 每个 Match2 In Matches2
sweb = Match2
Debug.Print结果& dweb.Exists(result)
如果 dweb.Exists(result)= False 然后
dweb.Add(结果), 1
List2.AddItem结果
哔哔
结束 如果
下一步
" regweb.IgnoreCase = True ' Set case insensitivity. regweb.Global = True ' Set global applicability. result = Inet1.OpenURL(dsource) Set Matches2 = regweb.Execute(dsource) For Each Match2 In Matches2 sweb = Match2 Debug.Print result & dweb.Exists(result) If dweb.Exists(result) = False Then dweb.Add (result), 1 List2.AddItem result Beep End If Next



请检查并帮助我。谢谢


Please check and help me.Thanks


1。在代码的顶部,你应该总是使用Option Explicit

2.之后,添加这个注释:'需要项目参考Microsoft VBScript正则表达式5.5

3 。并且'需要项目组件'Microsoft Internet Transfer Control 6.0

4.用以下内容替换您的代码



Dim iFile As Integer

Dim dsource As String

昏暗的结果

Dim regweb As Object

Dim bBIN()As Byte

dsource =http://www.google.lt/search?num=100&q=&Text2.Text

设置regweb = New RegExp'创建正则表达式。

regweb.Pattern =http:// \b\w + \\\\\(net | com | us | org | ru | lt | co.uk | tr | info(ftp | telnet)\ *
1. At the top of your code, you should always use Option Explicit
2. After that, add this comment: 'Requires Project Reference "Microsoft VBScript Regular Expressions 5.5"
3. And 'Requires Project Component "Microsoft Internet Transfer Control 6.0"
4. Replace your code with the following

Dim iFile As Integer
Dim dsource As String
Dim result
Dim regweb As Object
Dim bBIN() As Byte
dsource = "http://www.google.lt/search?num=100&q=" & Text2.Text
Set regweb = New RegExp ' Create a regular expression.
regweb.Pattern = "http://\b\w+\s\\(net|com|us|org|ru|lt|co.uk|tr|info(ftp|telnet)\*




regweb.IgnoreCase = True'设置不区分大小写。

regweb.Global = True'设置全局适用性。

bBIN = Inet1.OpenURL(dsource,icByteArra y)

iFile = FreeFile

打开C:\ temp\temp.txt进行二进制访问写为iFile

Put# iBile,bBIN

关闭iFile

'设置匹配2 = regweb.Execute(dsource)

'每场比赛2匹配2

'bweb = Match2

'Debug.Print result&dweb.Exists(result)

'如果dweb.Exists(result)= False那么

'dweb.Add(结果),1

'List2.AddItem结果

'Beep

'结束如果

'下一页



5.检查C:\ temp \ temp.txt的内容,为什么其余部分会很清楚您的代码失败了。



6.将来,我建议您在将代码混合在一起并将其粘贴到其他人的论坛上之前尝试更好的调试技术并阅读文档为你做你的工作。例如,Set Matches2 = regweb.Execute(dsource)完全没有意义。祝你好运。
"
regweb.IgnoreCase = True ' Set case insensitivity.
regweb.Global = True ' Set global applicability.
bBIN = Inet1.OpenURL(dsource, icByteArray)
iFile = FreeFile
Open "C:\temp\temp.txt" For Binary Access Write As iFile
Put #iFile, , bBIN
Close iFile
'Set Matches2 = regweb.Execute(dsource)
'For Each Match2 In Matches2
'sweb = Match2
'Debug.Print result & dweb.Exists(result)
'If dweb.Exists(result) = False Then
'dweb.Add (result), 1
'List2.AddItem result
'Beep
'End If
'Next

5. Examine the contents of C:\temp\temp.txt, and it will be very clear why the rest of your code was failing.

6. In the future, I suggest you try better debugging techniques and reading the documentation before hobcobbling code together and pasting it on forums for others to do your work for you. For example, "Set Matches2 = regweb.Execute(dsource)" makes no sense at all. Good luck.


这篇关于如何使vb6的正则表达式匹配代码来提取域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆