开发者

extract data from multiple places with regex

开发者 https://www.devze.com 2023-02-14 09:36 出处:网络
I have some html code and I want to get two things from it. Here is a bit of the code (the rest is just the same)

I have some html code and I want to get two things from it.

Here is a bit of the code (the rest is just the same) <a href="http://url.com/dir?get" target="_blank"><strong>lorem.ipsum</strong></a> </td> <td align="center"> 2011-02-27<br />14:19:18</td> <td style="padding: 0px" align="center"> <a href="http://url.com/dir?get=1234"><strong>Lorem</strong></a> </td> <td align="center" id="vote_10213"> <strong>2</strong></a><br /><a class="sublink" href="#" onclick="return requestvote(10213)"&g开发者_如何学Pythont;<strong>[Add&nbsp;vote]</strong></a></td>

And from this I want to extract lorem.ipsum between the strong tags and the number in the requestvote().

This is what I have:

/_blank"><strong>([^<]+)<\/strong>(.*)requestvote\(([^\']+)\)/s

But it takes everything in between too. Which I don't want. I use php:

preg_match_all('/_blank"><strong>([^<]+)<\/strong>(.*)requestvote\(([^\']+)\)/s', $response, $match);


You were almost right:

preg_match_all('/_blank"><strong>(.*?)<\/strong>.*?requestvote\((.*?)\)/s', $response, $match);
0

精彩评论

暂无评论...
验证码 换一张
取 消