有这个字符串:
$var = "30.5x120.8 (test desc here)";
我需要用正则表达式得到30.5和120.8。。有什么帮助吗??Thx
preg_match_all('~'d+(?:'.'d+)?~', $string, $matches);
var_dump($matches[0]);
$var = "30x120 (test desc here)";
preg_match_all('/^('d+)x('d+)/', $var, $matches);
var_dump($matches)
Ideone。
输出
array(3) {
[0]=>
array(1) {
[0]=>
string(6) "30x120"
}
[1]=>
array(1) {
[0]=>
string(2) "30"
}
[2]=>
array(1) {
[0]=>
string(3) "120"
}
}
更新
也适用于17.5x17.5?
这是一个将。。。
/^('d+(?:'.'d+)?)x('d+(?:'.'d+)?)/
Ideone。
preg_match('/^('d+)x('d+)/', '30x120 (test desc here)', $result);
并使用CCD_ 1和CCD_ 2
以下内容应该可以完成任务:/^('d+)x('d+)/
运行代码