Results 1 to 7 of 7

Thread: [RESOLVED] Regex Help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Resolved [RESOLVED] Regex Help

    I need to get the number in this url which is will be contained in the webbrowser1.documenttext, there will only be one on the page
    example:
    Code:
    http://www.facebook.com/profile.php?id=100001473886&ref=search
    I just need the 100001473886

  2. #2
    New Member Firestarter_75's Avatar
    Join Date
    Aug 2010
    Posts
    9

    Re: Regex Help

    Tddupre,

    Try this:

    Code:
    Dim searchstring As String = "http://www.facebook.com/profile.php?id=100001473886&ref=search"
    Dim idmatch As Match = Regex.Match(searchstring, "(?<=id\=)\d*(?=\&ref)")
    If idmatch.Success Then
        MessageBox.Show(idmatch.Value)
    Else
        MessageBox.Show("No match found.")
    End If
    Hope this helps

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Re: Regex Help

    Quote Originally Posted by Firestarter_75 View Post
    Tddupre,

    Try this:

    Code:
    Dim searchstring As String = "http://www.facebook.com/profile.php?id=100001473886&ref=search"
    Dim idmatch As Match = Regex.Match(searchstring, "(?<=id\=)\d*(?=\&ref)")
    If idmatch.Success Then
        MessageBox.Show(idmatch.Value)
    Else
        MessageBox.Show("No match found.")
    End If
    Hope this helps
    this does help, but i need it to search the entire html text and find the number

  4. #4
    New Member Firestarter_75's Avatar
    Join Date
    Aug 2010
    Posts
    9

    Re: Regex Help

    Have you tried this example?

    Have you tried changing the searchstring to something similar:

    Code:
    Dim searchstring As String = WebBrowser1.DocumentText

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    84

    Re: Regex Help

    Quote Originally Posted by Firestarter_75 View Post
    Have you tried this example?

    Have you tried changing the searchstring to something similar:

    Code:
    Dim searchstring As String = WebBrowser1.DocumentText
    yea i tried that, but it came up with no results

  6. #6
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: Regex Help

    Try this as your regular expression:

    Code:
    id=(\d+)&?
    Last edited by Zach_VB6; Aug 18th, 2010 at 06:24 PM.

  7. #7
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Regex Help

    the regex.match function returns only the first match found in the string. If you want to find all matches from a string, call regex.matches function instead and it will return a matchcollection which you can loop through each match and read the value.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width