Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.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
Php 意外的正则表达式行为_Php_Regex - Fatal编程技术网

Php 意外的正则表达式行为

Php 意外的正则表达式行为,php,regex,Php,Regex,所以我承认我对正则表达式不太熟悉,但我正试图从字符串中提取货币 我已经尝试了一系列的正则表达式,它们被认为是“用于”PHP的,但似乎没有任何效果。所以我回到了最基本的部分 图案 \$\d* 串 2009 Low Price -- One Owner $8800 OBO 我能够通过以下方式测试/验证此模式: 但是当我跑的时候 $pattern = "/\$\d*/"; $match = preg_match_all($pattern, $this->Title, $mat

所以我承认我对正则表达式不太熟悉,但我正试图从字符串中提取货币

我已经尝试了一系列的正则表达式,它们被认为是“用于”PHP的,但似乎没有任何效果。所以我回到了最基本的部分

图案

\$\d*

2009 Low Price -- One Owner $8800 OBO
我能够通过以下方式测试/验证此模式:

但是当我跑的时候

    $pattern = "/\$\d*/";
    $match = preg_match_all($pattern, $this->Title, $matches);
    echo $matches[0][0];
我没有得到任何结果。。。我也尝试过使用

$pattern = "/\\$\d*/";

有人知道为什么会这样吗?还是我遗漏了一些非常明显的东西

编辑


使用PHP5.5.11,在OSX上,我认为它是一个特定于实例的..?

尝试此模式以匹配货币值

~\$\d+~
你的代码是

<?php
$data = "2009 Low Price -- One Owner $8800 OBO";
$regex =  '~\$\d+~';
preg_match_all($regex, $data, $matches);
var_dump($matches);
?>

这仍然没有返回任何结果它对我有效。你能用ideone粘贴代码吗?
<?php
$data = "2009 Low Price -- One Owner $8800 OBO";
$regex =  '~\$\d+~';
preg_match_all($regex, $data, $matches);
var_dump($matches);
?>
array(1) {
  [0]=>
  array(1) {
    [0]=>
    string(5) "$8800"
  }
}