Click here to Skip to main content
14,603,732 members
Rate this:
Please Sign up or sign in to vote.
See more:
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
Posted
Comments
Member 10018770 22-Jan-15 3:09am
   
Nobody have there for help me?
Richard MacCutchan 22-Jan-15 3:27am
   
You only posted this message an hour ago. People respond to questions here in their own time, so learn to be patient. It would also help if you explained clearly what is wrong with the above code.
Member 10018770 22-Jan-15 3:33am
   
Sorry !. I have explained that obove code show nothing (No error - No Result)

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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 ' 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.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100