【问题标题】:preg_match digit sequence separated by a characterpreg_match 由字符分隔的数字序列
【发布时间】:2013-02-24 01:13:48
【问题描述】:

如何在<div class="lot-price-block"> 之间查找由字符“-”分隔并以<span 结尾的两位数字。

我试过了

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

但它给了我所有的块,不仅是由'-'分隔的数字

有人知道吗?

【问题讨论】:

    标签: preg-match digit


    【解决方案1】:

    试试这样的:

    $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 => 匹配所有非数字 ([^0-9])

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

    ps:你不需要转义连字符

    【讨论】:

      猜你喜欢
      • 2012-02-13
      • 1970-01-01
      • 2010-10-19
      • 2014-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      相关资源
      最近更新 更多