我拆分了一个字符串'3(1-5)‘如下:
$pattern = '/^(\d+)\((\d+)\-(\d+)\)$/';
preg_match($pattern, $string, $matches);
但我需要对小数做同样的事情,即'3.5(1.5-4.5)‘。如果用户写“3,5(1,5-4,5)”,我该怎么办?
“3.5(1.5-4.5)”的产出应为:
$matches[1] = 3.5
$matches[2] = 1.5
$matches[3] = 4.5
发布于 2014-10-12 19:13:59
这一模式应有助于:
^(\d+\.?\,?\d+)\((\d+\,?\.?\d+)\-(\d+\.?\,?\d+)\)$
https://stackoverflow.com/questions/26328858
复制相似问题