为什么regex找不到字符串


why regex cannot find string?

字符串为:Byredo Perfume Oil Roll On Blanche 7.5ML我想从字符串中获得7.5

$productinfo['title'] = 'Estee Lauder Sensuous Noir EDP 50ML';
if (preg_match('/.*'s('d+)'s?ml/', strtolower($productinfo['title'])))
{
preg_match('/.*'s('d+)'s?ml/', strtolower($productinfo['title']), $C);
$mlsize = $C[1];
echo $mlsize;
    }

这个代码工作得很好。我从这段代码中得到了50。但是,当$productioninfo['title']等于:Byredo Perfume Oil Roll On Blanche 7.5ML时,代码不起作用。我想从字符串

中获得7.5
.*'s('d*(?:'.'d+)?)'s?ml

试试这个。请参阅演示。正则表达式不起作用的原因是您正在捕获整数,但有.,即它是一个浮点值。要捕获浮点值,请使用此正则表达式。

http://regex101.com/r/tF5fT5/45

$re = "".*''s(''d*(?:''.''d+)?)''s?ml"i";
$str = "Byredo Perfume Oil Roll-On Blanche 7.5ML ";
preg_match_all($re, $str, $matches);