Results 1 to 7 of 7

Thread: Regex doesn't working

  1. #1

    Thread Starter
    Addicted Member JackIlPazzo's Avatar
    Join Date
    Oct 2014
    Posts
    183

    Regex doesn't working

    I make this regex to grab content from internet page:

    Code:
    Regex.Match(HTML, "'block_competition_matches', ({[\w\s"",:]+})").Groups(1).ToString
    webpage.


    But regex return false, what isn't correct?

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Regex doesn't working

    After 60 posts on this forum you should know by now to include detail. "It doesn't work whats wrong" is simply expecting members to guess what parts of the data you want to capture, work out whats happening and whats going wrong. Most members will ignore threads like these.

    You already know whats wrong. I's the regex pattern. How much regex have you studied? Can you please show what part of the HTMl you actually want.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    311

    Re: Regex doesn't working

    From the link given, the pattern 'block_competition_matches', doesn't exist so the entire match including the group would not exist. The closest was 16 matches to block_competition_matches, but each of those is then followed by _summary_6 which is not what your pattern is looking for. What exactly are you trying to match (not just the text you are using for HTML, but an example string from that webpage that contains what you are trying to match).

  4. #4

    Thread Starter
    Addicted Member JackIlPazzo's Avatar
    Join Date
    Oct 2014
    Posts
    183

    Re: Regex doesn't working

    Quote Originally Posted by Pyth007 View Post
    From the link given, the pattern 'block_competition_matches', doesn't exist so the entire match including the group would not exist. The closest was 16 matches to block_competition_matches, but each of those is then followed by _summary_6 which is not what your pattern is looking for. What exactly are you trying to match (not just the text you are using for HTML, but an example string from that webpage that contains what you are trying to match).
    To give you an example clear, I in my previous code I used this:

    Code:
    Dim HTML As String = New WebClient().DownloadString(URLs(MetroComboBox2.SelectedIndex))
            Dim URL_Params As String = "&callback_params=" & Regex.Match(HTML, "'block_competition_playerstats', ({[\w\s"",:]+})").Groups(1).ToString
            MessageBox.Show(URL_Params.ToString)
    How you can see, I save in HTML variable the contents of the page, so in the "URL_Params" I've the all div block of the HTML table existing in the HTML variable.
    The content that i get is:

    Name:  s.JPG
Views: 154
Size:  13.9 KB

    So, now i Want to catch another table available in this link.

    And i make this code:

    Code:
     Dim HTML As String = New WebClient().DownloadString(URLs(MetroComboBox2.SelectedIndex))
                  Dim URL_Params As String = "&callback_params=" & Regex.Match(HTML, "'block_competition_matches_summary_6', ({[\w\s"",:]+})").Groups(1).ToString
            MessageBox.Show(URL_Params.ToString)
    But the regex don't catch the value but these are available on the page.

  5. #5
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Regex doesn't working

    Your first post the query was block_competition_matches, but now it is block_competition_matches_summary_6. This is why i asked for you to be clear because i do't want to keep coming back and forth. This is why i also said can you please post the exact match you want from the source.

    With the query text you provided

    vb Code:
    1. block_competition_matches_summary_6_match-1836425\" data-competition=13><td class=\"day no-repetition\"><span class='timestamp' data-value='1420552800' data-format='ddd'>mar<\/span><\/td><td class=\"date no-repetition\"><span class='timestamp' data-value='1420552800' data-format='dd\/mm\/yy'>06\/01\/15<\/span><\/td><td class=\"team team-a \"><a href=\"\/teams\/italy\/genoa-cfc\/1276\/\" title=\"Genoa\">Genoa<\/a><\/td>

    so can you be so kindly to show me right after that query you provided is there any curly brackets.....Because there is not.

    Code:
    block_competition_matches_summary_6 .match-pagination {margin-bottom: 0.7em;}
    Now is the line you want to match because you have seemed to ignore ".match-pagination" in your matching if this is the line in question.

    vb Code:
    1. Imports System.Text.RegularExpressions
    2.  
    3. Public Class Form1
    4.  
    5.     Private Sub FindMatches(url As String)
    6.         Dim source As String = GetPagesSource(url)
    7.  
    8.         If source IsNot Nothing Then
    9.             Dim pattern As String = "(?<=summary_6 \.match-pagination ).+?(?=<)"
    10.             Dim rx As New Regex(pattern)
    11.  
    12.             MessageBox.Show("&callback_params=" & rx.Match(source).Value)
    13.         End If
    14.     End Sub
    15.  
    16.     Private Function GetPagesSource(url As String) As String
    17.         Dim source As String = Nothing
    18.  
    19.         Using wClient As New Net.WebClient()
    20.             Try
    21.                 source = wClient.DownloadString(New Uri(url))
    22.             Catch ex As Exception
    23.                 ' handle gracefully
    24.             End Try
    25.         End Using
    26.  
    27.         Return source
    28.     End Function
    29. End Class

    This is why i previously asked for a full and clear description. Just because something is clear to you it might to be to us. Each member who asks a question time is important to us. His/hers problem is important to us. If we spend lots of time going back and forth it takes time away from others. We don't like guess work.

  6. #6

    Thread Starter
    Addicted Member JackIlPazzo's Avatar
    Join Date
    Oct 2014
    Posts
    183

    Re: Regex doesn't working

    Quote Originally Posted by ident View Post
    Your first post the query was block_competition_matches, but now it is block_competition_matches_summary_6. This is why i asked for you to be clear because i do't want to keep coming back and forth. This is why i also said can you please post the exact match you want from the source.

    With the query text you provided

    vb Code:
    1. block_competition_matches_summary_6_match-1836425\" data-competition=13><td class=\"day no-repetition\"><span class='timestamp' data-value='1420552800' data-format='ddd'>mar<\/span><\/td><td class=\"date no-repetition\"><span class='timestamp' data-value='1420552800' data-format='dd\/mm\/yy'>06\/01\/15<\/span><\/td><td class=\"team team-a \"><a href=\"\/teams\/italy\/genoa-cfc\/1276\/\" title=\"Genoa\">Genoa<\/a><\/td>

    so can you be so kindly to show me right after that query you provided is there any curly brackets.....Because there is not.

    Code:
    block_competition_matches_summary_6 .match-pagination {margin-bottom: 0.7em;}
    Now is the line you want to match because you have seemed to ignore ".match-pagination" in your matching if this is the line in question.

    vb Code:
    1. Imports System.Text.RegularExpressions
    2.  
    3. Public Class Form1
    4.  
    5.     Private Sub FindMatches(url As String)
    6.         Dim source As String = GetPagesSource(url)
    7.  
    8.         If source IsNot Nothing Then
    9.             Dim pattern As String = "(?<=summary_6 \.match-pagination ).+?(?=<)"
    10.             Dim rx As New Regex(pattern)
    11.  
    12.             MessageBox.Show("&callback_params=" & rx.Match(source).Value)
    13.         End If
    14.     End Sub
    15.  
    16.     Private Function GetPagesSource(url As String) As String
    17.         Dim source As String = Nothing
    18.  
    19.         Using wClient As New Net.WebClient()
    20.             Try
    21.                 source = wClient.DownloadString(New Uri(url))
    22.             Catch ex As Exception
    23.                 ' handle gracefully
    24.             End Try
    25.         End Using
    26.  
    27.         Return source
    28.     End Function
    29. End Class

    This is why i previously asked for a full and clear description. Just because something is clear to you it might to be to us. Each member who asks a question time is important to us. His/hers problem is important to us. If we spend lots of time going back and forth it takes time away from others. We don't like guess work.
    Sorry, I missed the link, this is correct link:

    http://it.soccerway.com/national/ita...season/r27139/

    this is the table:

    Name:  table.jpg
Views: 123
Size:  40.7 KB

    Thank you for the response.

  7. #7
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Regex doesn't working

    That is a link and yes that is a table. But you have not said WHAT line you want to match.

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