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.
这是一个简短的正则表达式示例:
preg_match_all('~(\s+|/)(\d{2})?\s*–\s*(\d{2})?$~u', 'i love regex 00– / 03–08', $matches); print_r($matches);
正则表达式只匹配“03–08”,但我的意图也是匹配“00–”。问题是什么?谁能解释一下?
最后的部分:
-\s*(\d{2})?$~u
意味着您的匹配项和字符串结尾之间只能有空格和/或可选的两位数。这意味着00-无法匹配,因为它和字符串末尾之间还有其他东西。
00-
如果您删除$,它应该可以按您的意愿工作。
$