Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个字符串:
$style = "width:87.0%;";
如何使用 PHP preg_match() 从中提取“87”?对于我的一生,我无法在正则表达式周围得到我的头套:(
preg_match('/:(.*?)\./', $style, $matches); echo $matches[1];
这?使得正则表达式不情愿/不贪婪
?
preg_match('~:(\d+)\.~', 'width:87.0%;', $m); print_r($m); print $m[1]; // 87
\d只有数字,+一次或多次,()将其分组(捕获)以供以后使用。
\d
+
()