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.
我需要一个正则表达式,如果有一个数字后跟一个百分号,它将在我的字符串开头搜索并提取它。
$string = "20% - some text"; preg_match('/^[0-9]+%$/',$string);
应该返回 20%
您应该使用以下$matches参数:
$matches
$string = "20% - some text"; $matches = array(); if (preg_match('/^([0-9]+%)/', $string, $matches)) { print_r($matches); }