我想從字符串$123/123 - 1425ft² - Some random message
中提取整數1425
。但是,我只能提取5
而不是1425
以下面的代碼。PHP正則表達式匹配一個數字
在正則表達式中,我使用*
來匹配多個數字。
有什麼建議出了什麼問題?謝謝!
PHP
$text = '$123/123 - 1425ft² - Some random message';
$pattern = '/ ([0-9])*ft²/s';
preg_match($pattern, $text, $matches);
echo '<pre>';
print_r($matches);
輸出
Array
(
[0] => 1425ft²
[1] => 5
)
移動捕獲組捕獲所有的數字:''/([0-9] +)平方英尺/ s'' – nhahtdh 2013-03-04 08:58:48
你需要移動的星星* *裏面的圓括號,以便捕獲組「()」包含所有匹配的數字。 – Jon 2013-03-04 08:59:01
@nhahtdh這有效! – Nyxynyx 2013-03-04 08:59:29