Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Locating very specific URL in HTML code

Last post 02-08-2010, 1:34 PM by seraphx2. 2 replies.
Sort Posts: Previous Next
  •  02-08-2010, 11:57 AM 59412

    Locating very specific URL in HTML code

    Language/Platform: VB.NET 2008
    Project: I am creating a program to search HTML source code for a very specific URL string.
    Issue: I am not good with these regular expressions at all and am having trouble getting what I need.

    Here is what I have so far in VB.NET:

            Dim testNum As MatchCollection = Regex.Matches(TextBox1.Text, "<a href='series.php\?ID=[0-9]'>[^</a>]</a>")

            If testNum.Count = 0 Then
                End
            Else
                MessageBox.Show(testNum.Count)
            End If

    Expression: <a href='series.php\?ID=[0-9]'>[^</a>]</a>

    Sample Text:

    <a href='series.php?ID=23'>Aishiteru ze Baby ( Love You Baby )</a>
    <a href='series.php?ID=230'>Akage no Anne ( Anne of Green Gables )</a>

    There is an ID number that is variable in Integer value and length directly after ID=.

    Between the HTML anchor tags, there is variable text that can have any length and any characters.

    I run my code and no values are being returned (The count of the Match collection is 0).

    I know my code is correct because if I just do a search for a single character, I get results. ("a" = 14 matches)

     

    So, I'm totally lost and have no idea what is wrong with my code as, for some reason, I am totally not grasping this RegEx thing entirely and what constitutes an illegal expression.

    Thanks for any help provided.

  •  02-08-2010, 12:55 PM 59415 in reply to 59412

    Re: Locating very specific URL in HTML code

     try

    <a href='series.php\?ID=\d+'>[^<]+</a>

    u sh get 2 matches:

    <a href='series.php?ID=23'>Aishiteru ze Baby ( Love You Baby )</a>
    <a href='series.php?ID=230'>Akage no Anne ( Anne of Green Gables )</a>

    u need to read on using the character class [...]

    and quantifiers like  \d+ when u are trying to match on "230"

    [0-9]    will fail to match on '230"

     

  •  02-08-2010, 1:34 PM 59420 in reply to 59415

    Re: Locating very specific URL in HTML code

    Thank you.  Took me a minute to understand why that worked but I get it.  Thanks so much.

    I've already learned alot more with this one issue than I have in a while.

    I've tried reading regular-expressions.info but was having trouble understanding it.

    Looking at what you did and then looking up the explanations what the parts were doing makes much more sense.

     

    Thanks :)

View as RSS news feed in XML