-2
我有一個字符串:如何解決preg_match():未知修飾符'{'?
$11,950 Some random string $415
,我想分析第一價格信息爲整數:
11950
爲了獲得與thouand分離器中的第一個數字的一部分,我創建了一個正則表達式:
[0-9]{1,3}(,[0-9]{3})*(\.[0-9]+)?
上online regex editor預期其工作。
然而,當我使用它的preg_match
:
$price = 0;
$content = '$11,950 Some random string $415';
if (preg_match('[0-9]{1,3}(,[0-9]{3})*(\.[0-9]+)', $content, $matches)) {
var_dump($matches[0]);
}
我得到一個錯誤:
preg_match(): Unknown modifier '{'
我在做什麼錯?
'的preg_match('/ [0-9] {1,3}([0-9] {3})*(\ [0-9] + )/',$ content,$ matches)' – anubhava
請閱讀[分隔符](http://php.net/manual/en/regexp.reference.delimiters.php) –