Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java正则表达式问题_Java_Regex - Fatal编程技术网

Java正则表达式问题

Java正则表达式问题,java,regex,Java,Regex,有一个网站,我想解析什么。来源如下 <tr> <td><a href="http://www.z104.com/"><b>WNVZ</b></a> - Z104</td> <td>Norfolk</td> <td>Virginia</td> <td><img src="mp3.gif" alt="MP3" width="12" heigh

有一个网站,我想解析什么。来源如下

 <tr> <td><a
 href="http://www.z104.com/"><b>WNVZ</b></a>
 - 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">64
 Kbps</a></td> <td>Top 40</td> </tr>

 <tr> <td><a
 href="http://www.z104.com/"><b>WNVZ</b></a>
 - 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">64
 Kbps</a></td> <td>Top 40</td> </tr>

-Z104弗吉尼亚州诺福克市前40名
-Z104弗吉尼亚州诺福克市前40名
。。。等

如何从中剪切所有数据,我想使用regexp,返回我需要的字符串:

WNVZ-Z104#诺福克#弗吉尼亚#http://provisioning.streamtheworld.com/pls/WNVZFM.pls#Top 四十

WNVZ-Z104#诺福克#弗吉尼亚#http://provisioning.streamtheworld.com/pls/WNVZFM.pls#Top 40 等等

所以,我想把所有这些都剪掉,字符串是“.pls”或“.m3u”


对不起,我的英语糟透了。

用正则表达式解析HTML很困难;使用诸如SAX之类的XML解析器可能会更幸运。

使用正则表达式解析HTML是困难的;使用诸如SAX之类的XML解析器可能会更幸运。

不要尝试使用regexp,因为HTML不是规则的,而且边缘大小写的数量会使编写regexp变得不可能。相反,您将获得一个更可靠的解决方案,使用HTML解析器,例如。

不要尝试使用regexp,因为HTML不是规则的,而且边缘案例的数量将使编写regexp变得不可能。相反,您将使用HTML解析器获得更可靠的解决方案,例如。

如果您坚持使用正则表达式,我为您制作此正则表达式:

搜索:

  <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>

如果您坚持使用正则表达式,我将为您制作此正则表达式:

搜索:

  <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>