Need help to get Regex.Match strings
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Need help to get Regex.Match strings

  1. #1
    Join Date
    Aug 2007
    Posts
    447

    Need help to get Regex.Match strings

    Hi all,

    I would like you to help me out with the strings, which I find it difficulty to get from the html class. The first string I uses as pattern1 string, which it connected to the server to get the showtitle string from the html class, it is working fine. I couldn't be able to get the string on the second paragraph from the html class with pattern2 string, as the text goes on the blank. I need to get the string from the html class. The third pattern string, I am trying to get the string at the end of the html class so I got the blank text.


    Here it is the form code:

    Code:
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            'Create a request for the URL.        
            Dim request As WebRequest = WebRequest.Create("http://blog.zingzing.co.uk/channels?channel=55")
            ' If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials
            ' Get the response.
            Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
            ' Display the status.
            Console.WriteLine(response.StatusDescription)
            ' Get the stream containing content returned by the server.
            Dim dataStream As Stream = response.GetResponseStream()
            ' Open the stream using a StreamReader for easy access.
            Dim reader As New StreamReader(dataStream)
            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()
            ' Display the content.
            reader.Close()
            dataStream.Close()
            response.Close()
            ' Cleanup the streams and the response.
    
    
    
            Dim pattern As String = "(?<=class=""showTitle""\>\<a href\=.+?""\>).+(?=\<\/a\>)"
            Dim m As Match = Regex.Match(responseFromServer, pattern)
            If m IsNot Nothing Then
                Label2.Text = m.Value
            End If
    
    
            Dim pattern1 As String = "(?<=class=""showchannel""\>)"
            Dim m1 As Match = Regex.Match(responseFromServer, pattern1)
            If m1 IsNot Nothing Then
                Label3.Text = m1.Value
            End If
    
    
    
     Dim pattern2 As String = "(1<<=class=""showTitle""\>>\<a href\=.+1""\>>).+(1=\<<\/a\>>)"
            Dim m2 As Match = Regex.Match(responseFromServer, pattern2)
            If m2 IsNot Nothing Then
                Label4.Text = m.Value
            End If
        End Sub


    I am trying to achieve my goal is to get the strings at the end of the html class. The code of html class for pattern1 string, I got from the website which here it is:



    Code:
        <p class="showchannel">Thursday 17th December, 11:00</p>


    I want to get the string of the time at the end of the html class which it would be "11:00". That would be the one that come next to the comma. And for pattern2 string, I am trying to acheive my goal by getting the "showtitle" string on the second paragraph from the html class. You can still see that each paragraph on the below html code have the same name of the showtitle string as the first paragraph. I can get the showtitle string on the first paragraph , but the second paragraph I couldn't be able to get the showtitle string. I still only get the showtitle string from the first paragraph. I want to get the showtitle string on the second paragraph from the html class. If I use the same code to get the string for both paragraph as the first one and the second one then I will get the same string in each label text from the first paragraph. Here it is the html class I got it from the site:



    Code:
       1. <h3 class="showTitle"><a href="http://www.zingzing.co.uk/s/ywiyyt">Newsround</a></h3>  
       2.                                         <p class="showChannel">Tuesday 15th December, 17:00</p>  
       3.                                         <p class="showDescription">CBBC. Daily news magazine keeping young viewers up to date on the latest stories and events happening at home and abroad. <img src="http://vbcity.com/emoticons/emotion-56.gif" alt="Sleep"> 15min.</p>  
       4.                                         <p class="showAiring">  
       5.                                             <a href="http://blog.zingzing.co.uk/programmes?programme=96512182">More Airings</a>  
       6.   
       7.                                         </p>  
       8.                                     </div>  
       9.                                   
      10.                                     <div class="showResult">  
      11.                                         <h3 class="showTitle"><a href="http://www.zingzing.co.uk/s/n2zmmw">The Weakest Link</a></h3>  
      12.                                         <p class="showChannel">Tuesday 15th December, 17:00, 17:15</p>  
      13.                                         <p class="showDescription">Anne Robinson presents the quick-fire general knowledge quiz in which contestants must decide at the end of each round which of their number should be eliminated. <img src="http://vbcity.com/emoticons/emotion-56.gif" alt="Sleep"> 45min.</p>  
      14.                                         <p class="showAiring">  
      15.   
      16.                                             <a href="http://blog.zingzing.co.uk/programmes?programme=95683591">More Airings</a>  
      17.                                         </p>  
      18.                                     </div>  
      19.                                   
      20.                                     <div class="showResult">  
      21.                                         <h3 class="showTitle"><a href="http://www.zingzing.co.uk/s/njg2og">BBC News at Six</a></h3>  
      22.                                         <p class="showChannel">Tuesday 15th December, 17:00, 18:00</p>  
      23.                                         <p class="showDescription">The latest national and international news stories from the BBC News team, followed by Weather. <img src="http://vbcity.com/emoticons/emotion-56.gif" alt="Sleep"> 30min.</p>  
      24.   
      25.                                         <p class="showAiring">  
      26.                                             <a href="http://blog.zingzing.co.uk/programmes?programme=64544250">More Airings</a>  
      27.                                         </p>  
      28.                                     </div>  
    
    <h3 class="showTitle"><a href="http://www.zingzing.co.uk/s/ywiyyt">Newsround</a></h3>
    										<p class="showChannel">Tuesday 15th December, 17:00</p>
    										<p class="showDescription">CBBC. Daily news magazine keeping young viewers up to date on the latest stories and events happening at home and abroad. Sleep 15min.</p>
    										<p class="showAiring">
    											<a href="http://blog.zingzing.co.uk/programmes?programme=96512182">More Airings</a>
    
    										</p>
    									</div>
    								
    									<div class="showResult">
    										<h3 class="showTitle"><a href="http://www.zingzing.co.uk/s/n2zmmw">The Weakest Link</a></h3>
    										<p class="showChannel">Tuesday 15th December, 17:00, 17:15</p>
    										<p class="showDescription">Anne Robinson presents the quick-fire general knowledge quiz in which contestants must decide at the end of each round which of their number should be eliminated. Sleep 45min.</p>
    										<p class="showAiring">
    
    											<a href="http://blog.zingzing.co.uk/programmes?programme=95683591">More Airings</a>
    										</p>
    									</div>
    								
    									<div class="showResult">
    										<h3 class="showTitle"><a href="http://www.zingzing.co.uk/s/njg2og">BBC News at Six</a></h3>
    										<p class="showChannel">Tuesday 15th December, 17:00, 18:00</p>
    										<p class="showDescription">The latest national and international news stories from the BBC News team, followed by Weather. Sleep 30min.</p>
    
    										<p class="showAiring">
    											<a href="http://blog.zingzing.co.uk/programmes?programme=64544250">More Airings</a>
    										</p>
    									</div>





    I am trying very hard to be successful using with Regex.Match singular function, but I still have no luck yet.




    I hope you guys can help!!!!!!!!!!


    Thanks,
    Mark
    Share on Google+

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,945

    Re: Need help to get Regex.Match strings

    Why use RegEx if you don't know it? You can search for REGEX EDITOR and get one that can help, but it's still something to learn.

    If you have a streamreader, you can get what you want using other methods, can't you? Seems like a simple task
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!
    Share on Google+

  3. #3
    Join Date
    Dec 2009
    Posts
    2

    Re: Need help to get Regex.Match strings

    Hi Mark103,

    What are you going to do with the data that you are pulling from the zingzing website?

    Regards,
    Marco
    Share on Google+

  4. #4
    Join Date
    Apr 2008
    Posts
    82

    Re: Need help to get Regex.Match strings

    @Moderator - see this thread and the threads it points to:

    http://www.vbforums.com/showthread.php?t=597587

    I am guessing Stephen100 at VBCity is Mark10x
    Share on Google+

  5. #5
    Join Date
    Dec 2009
    Posts
    2

    Re: Need help to get Regex.Match strings

    mark103,

    OK, for the second time.. Please refrain from copying data / code from the zingzing.co.uk website. It goes against our copyright & terms and conditions, as outlined on these pages:

    http://blog.zingzing.co.uk/copyright

    http://blog.zingzing.co.uk/terms-conditions

    And also in our source code... which you must of seen judging by your post!

    <!--
    ZingZing TV Schedule
    Copyright 2009 Marco Wolfsheimer - All rights reserved
    You may NOT copy, modify or redistribute any code, data or artwork contained within this site.
    Stealing source code is illegal.
    -->

    Could an admin please delete or lock this thread as it contains copyrighted material in the form of my source html. Here are my contact details should you have any questions:

    http://blog.zingzing.co.uk/contact

    Kind Regards,
    Marco Wolfsheimer
    (Zingzing Admin)
    Share on Google+

  6. #6
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Re: Need help to get Regex.Match strings

    Quote Originally Posted by mark103 View Post
    ...
    Dim pattern As String = "(?<=class=""showTitle""\>\<a href\=.+?""\>).+(?=\<\/a\>)"
    ...
    No, No

    (?<=matching expression here)

    means match a prefix, but exclude it from the capture.

    I suggest you to test your regular expresions with Ultrapico Expresso

    That software is excellent to learn and test those tricky RegExs.

    You can download and register it at no charge.
    Last edited by Marraco; January 4th, 2010 at 09:23 AM.
    [Vb.NET 2008 (ex Express)]
    Share on Google+

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: Need help to get Regex.Match strings

    [ Closed ]
    Share on Google+

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center