preg_match由字符分隔的数字序列

时间:2013-03-08 13:19:29

标签: preg-match digit

如何在<div class="lot-price-block"><span关闭之间找到由字符' - '分隔的两个数字。

我试过这个

preg_match_all('/<div class=\"lot\-price\-block\">(.*?)<span/s',$file_contents,$estimates);

但是它给了我所有的块,不仅是用' - '

分隔的数字

有人有任何想法吗?

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

$file_contents = '<div class="lot-price-block">fsfd 32424-554 fgdf <span';
preg_match_all('/<div class=\"lot-price-block\">\D*(\d+-\d+)\D*<span/s',$file_contents,$estimates);
echo $estimates[1][0];

\ D =&gt;匹配不是数字的所有内容([^ 0-9])

\ d =&gt;匹配所有数字([0-9])

ps:您不需要转义连字符