Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.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
正则表达式html标记数据_Html_Regex - Fatal编程技术网

正则表达式html标记数据

正则表达式html标记数据,html,regex,Html,Regex,我正在获取(HTTP请求),并试图通过使用正则表达式从中获取某些数据,例如HTML的这一部分: <tr><th>Continent:</th><td class='trc'>Europe (EU)</td></tr> 大陆:欧洲(欧盟) 我怎样才能让“欧洲(欧盟)”摆脱这种局面 我试过这个正则表达式: /<th>Continent:<\/th><td class='trc'>(.+)\

我正在获取(HTTP请求),并试图通过使用正则表达式从中获取某些数据,例如HTML的这一部分:

<tr><th>Continent:</th><td class='trc'>Europe (EU)</td></tr>
大陆:欧洲(欧盟)
我怎样才能让“欧洲(欧盟)”摆脱这种局面

我试过这个正则表达式:

/<th>Continent:<\/th><td class='trc'>(.+)\s<\/td>/
/大陆:(.+)\s/

但是这不起作用

您正在告诉正则表达式查找后跟

/大陆:(.+)\s/
^^
我建议使用
[^]+
在html标记之间搜索文本

/<th>Continent:<\/th><td class='trc'>([^<>]+)<\/td>/
/大陆:([^]+)/

您不应该使用正则表达式来解析HTML。使用HTML解析器实现这一点……这是针对mIRC脚本的,但我认为在mIRC脚本语言中正则表达式与PHP中的正则表达式是相同的?@plalx取决于使用成熟的SGML解析器提取单个数据的意图,就像用海军大炮攻击橡皮艇一样。与成熟的解析器相比,有很多用例更倾向于使用正则表达式从HTML中简单地提取一些简单的数据位。它通常也更具弹性,因为regex方法将在源页面结构的微小更改中幸存下来。
/<th>Continent:<\/th><td class='trc'>([^<>]+)<\/td>/