Regular Expressions Expert Needed

dsgreen57

Well-known member
Joined
Mar 31, 2003
Messages
66
I have to admit regular expressions elude me, I am terrible at them I am currently loading a website into a .NET class and then need to find whether a match was found.

Code:
<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"width:100%;border-collapse:collapse;\">
<tr class=\"litm_0\"><td align=\"Left\">Launch<br>SoundsLike<br>Station</td><td align=\"Left\">Album Name</td>
<td align=\"Left\">by Artist</td></tr><tr><td colspan=\"3\" style=\"background-color:#7D0000;\">
<img src=\"http://entimg.msn.com/i/sp.gif\" alt=\"\" border=\"0\" style=\"height:1px;width:1px;\" /></td>
</tr><tr class=\"litm_2\"><td><a href=\"/radio/launchradio.aspx?url=%2fsearch%2fDefault.aspx%3ftp%3dalbum%26ss%3dWaiting%2bFor%2bThe%2bPunch&amp;rcd=slalb1&amp;
type=album&amp;id=282060\"><img src=\"http://entimg.msn.com/i/radg.gif\" width=\"15\" height=\"15\"border=\"0\" 
alt=\"Play a SoundsLike station based on the album &quot;Waiting for the Punchline&quot;\" ></a></td><td>
<a class=\"subhead2\" href=\"/album/?album=282060\">Waiting for the Punchline</a></td><td>
<a href=\"/artist/?artist=101878\">Extreme</a></td></tr><tr class=\"litm_1\">

OK so to get these results I queried a website and then extracted just the results section, now I know by looking at the html that the correct part is the following :

Code:
href=\"/album/?=282060\">Waiting for the Punchline</a></t><td>

How can I write a regular expression, which would extract just that line I specifically need the artist ID, ie. I need to return 282060 from the method.
 
okay I have got closer to solving this..

Code:
System.Text.RegularExpressions.Regex myRegEx = new System.Text.RegularExpressions.Regex(@"album=(?<ID>\d*)");
System.Text.RegularExpressions.Match m;
  m = myRegEx.Match(html);
  if ( m.Success )
  {
    if ( m.Groups["ID"].Success )
    {
        return Convert.ToInt32(m.Groups["ID"].Value);
    }
  }
  else
  {
     return 0;
  }

This returns the first instance found what I need to do now is analyse the second part and return results which match the first part and are like Waiting for the Punch.
 
Back
Top