Marook-Online
* 06.Feb.2012, 15:00 UTC+1
Welcome, Guest. Please login or register.
Username:
Password:

News: Back again Wink
Main Menu
  Navigation
   Downloads
     Tools
     Music Discs
     SMF Mods
     Trainer & Patches
     EgoShare Uploader
   Guestbook
   NoPaste
   User Map
   Gallery
  
   Malware Scan
   Hacker Blacklist
   Find Abusemail
Top Downloads
Support Me !
Help me by donating a small amount!



Advanced search

Google


Pages: [1]   Go Down
0 Members and 1 Guest are viewing this topic. Topic Tools  
Read
19-Nov-2007 02:09
Marook
Administrator
*****
Offline Offline

Joined: 01-Jan-2005
Posts: 224


If you want to use RegEx like in many other languages you must simply do the following :

  • Add a reference to : Microsoft VBScript Regular Expressions 5.5
        File : \System32\vbscript.dll

Code
GeSHi (vb):
  1. 'Prepare a regular expression object
  2. Dim myRegExp As RegExp
  3. Dim myMatches As MatchCollection
  4. Dim myMatch As Match
  5. Set myRegExp = New RegExp
  6. myRegExp.IgnoreCase = True
  7. myRegExp.Global = True
  8. myRegExp.Pattern = "regex"
  9. Set myMatches = myRegExp.Execute(subjectString)
  10. For Each myMatch in myMatches
  11.  MsgBox(myMatch.Value)
  12. Next
Created by GeSHI 1.0.7.20

Copy+Paste-Ready-To-Use-Code Wink

Code
GeSHi (vb):
  1. Public Function sParseHref(sMatch As String, sHTML As String, Optional sClass As String = "", Optional MultiURLz As Boolean = False) As String
  2.   'returns a url that matches your sMatch string
  3.   Dim sPat As String, oHrefMatch As Variant
  4.   Dim objSrc As Variant, sHref As String
  5.   Dim rReg As RegExp
  6.   Dim oAnchorTag As Variant
  7.   Dim sHrefPat As String, objMatch As Variant
  8.   sParseHref = ""
  9.   Set rReg = New RegExp
  10.   sPat = "<A\s(.*?)>"
  11.   rReg.Pattern = sPat
  12.   rReg.Global = True
  13.   rReg.IgnoreCase = True
  14.   'Execute the regular expression on the raw HTML
  15.   Set oAnchorTag = rReg.Execute(sHTML)
  16.   'Step through our matches
  17.   For Each objMatch In oAnchorTag
  18.       sHrefPat = "href=""?(.*?)[\s"">]"
  19.       rReg.Pattern = sHrefPat
  20.       Set objSrc = rReg.Execute(objMatch.Value)
  21.       For Each oHrefMatch In objSrc
  22.            sHref = Trim(Replace(Replace(Replace(objMatch.Value, """", ""), "href=", "", 1, 1, 1), ">", ""))
  23.            Select Case Len(sClass)
  24.                Case 0
  25.                Case Else
  26.                    If InStr(1, sHref, "class=" & sClass) = 0 Then
  27.                        GoTo 2
  28.                    End If
  29.            End Select
  30.            sHref = Trim(Replace(Replace(Replace(oHrefMatch.Value, """", ""), "href=", "", 1, 1, 1), ">", ""))
  31.  
  32.           If InStr(1, sHref, sMatch, 1) > 0 Then
  33.                If MultiURLz = True Then
  34.                    sParseHref = sParseHref & sHref & "|"
  35.                Else
  36.                    sParseHref = sHref
  37.                    GoTo gotit
  38.                End If
  39.  
  40.           End If
  41.           DoEvents
  42. 2:
  43.       Next
  44.   Next
  45. gotit:
  46.   Set objSrc = Nothing
  47.   Set rReg = Nothing
  48.   Set objMatch = Nothing
  49.   Set oAnchorTag = Nothing
  50. End Function
  51.  
Created by GeSHI 1.0.7.20

Usage:
Code
GeSHi (vb):
  1.    Dim xmlHTTP As Object
  2.    Dim tmp()   As String
  3.  
  4.    Set xmlHTTP = CreateObject("Microsoft.XMLHTTP")
  5.  
  6.    xmlHTTP.open "GET", "http://www.google.de/search?hl=de&q=visual+basic&meta="
  7.    xmlHTTP.send
  8.  
  9.    Do Until xmlHTTP.readyState = 4
  10.        DoEvents
  11.    Loop
  12.  
  13.    'Put all found urls in an array
  14.    tmp() = Split(sParseHref("vb", xmlHTTP.responsetext, , True), "|")
  15.  
  16.    'Or just return the first found url on wikipedia
  17.    MsgBox sParseHref("wiki", xmlHTTP.responsetext)
  18.  
Created by GeSHI 1.0.7.20
« Last Edit: 19-Nov-2007 02:41 by Marook » Logged
 

Pages: [1]   Go Up
Jump to:  

Theme by webtechnica.net

MHD v2.1 © 2oo8 by Marook
32116 hacking attempts defended!