tags:

views:

51

answers:

3

There is a web site, what i want to parse. The source is the following

 <tr> <td><a
 href="http://www.z104.com/"&gt;&lt;b&gt;WNVZ&lt;/b&gt;&lt;/a&gt;
 - Z104</td> <td>Norfolk</td> <td>Virginia</td> <td><img
 src="mp3.gif" alt="MP3" width="12"
 height="12"></td> <td><a
 href="http://provisioning.streamtheworld.com/pls/WNVZFM.pls"&gt;64
 Kbps</a></td> <td>Top 40</td> </tr>

 <tr> <td><a
 href="http://www.z104.com/"&gt;&lt;b&gt;WNVZ&lt;/b&gt;&lt;/a&gt;
 - Z104</td> <td>Norfolk</td> <td>Virginia</td> <td><img
 src="mp3.gif" alt="MP3" width="12"
 height="12"></td> <td><a
 href="http://provisioning.streamtheworld.com/pls/WNVZFM.pls"&gt;64
 Kbps</a></td> <td>Top 40</td> </tr>

... etc

How can i cut all the datas from it, i d like to use a regexp, the return string what i need:

WNVZ - Z104#Norfolk#Virginia#http://provisioning.streamtheworld.com/pls/WNVZFM.pls#Top 40

WNVZ - Z104#Norfolk#Virginia#http://provisioning.streamtheworld.com/pls/WNVZFM.pls#Top 40 etc.

so, i want to cut all of this, where the string is ".pls" or ".m3u"

sorry my english is shit.

+2  A: 

Parsing HTML with a regex is difficult; you might have better luck using an XML parser such as SAX.

Nick
+1  A: 

Don't try to use regexps, since HTML isn't regular, and the number of edge cases will make coding a regexp impossible. Instead you'll have a more reliable solution using an HTML parser such as JTidy.

Brian Agnew
A: 

If you insists to use regex, I make this regex for you:

Search for:

  <tr\b[^><]*>\s*<td\b[^><]*>\s*<a\b[^><]*>\s*<b>\s*(WNVZ)\s*<\/b>\s*<\/a>\s*-\s*(\w+)<\/td>\s*<td\b[^><]*>\s*(Norfolk)\s*<\/td>\s*<td\b[^><]*>\s*(Virginia)\s*</td>\s*<td\b[^><]*>\s*<img\b[^><]*>\s*</td>\s*<td\b[^><]*>\s*<a\b[^><]*href\s*=\s*["']([^"'><]+)["'][^><]*>[^><]*<\/a>\s*<\/td>\s*<td\b[^><]*>([^><]*)</td>

Replace with:

  $1 - $2#$3#$4#$5#$6
Vantomex