Php 意外的正则表达式行为
所以我承认我对正则表达式不太熟悉,但我正试图从字符串中提取货币 我已经尝试了一系列的正则表达式,它们被认为是“用于”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
\$\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"
}
}