我有一個正則表達式:PHP的preg_match匹配錯誤的字符串
/\/(register)(?:\/activate\/(.{16}))?(?:\/(student|teacher|org))?\/?$/
正確匹配,字符串:
/register
/register/student
/register/activate/123456789/
不匹配問題:
/register/register/register/register/student/
上面,而在使用的preg_match仍然匹配PHP。任何替代品?
我也試圖限制 '註冊',以1:
\/((?:register){1})(?:\/activate\/(.{16}))?(?:\/(student|teacher|org))?\/?$
沒有運氣。
它不符合使用Debuggex,但它匹配使用http://www.phpliveregex.com/
哦,是的,謝謝!我對所有其他表情都有這種看法,我想在經過多次編輯後,它會以某種方式被刪除。 –
另外,使用另一個字符(例如〜或#)來分隔您的模式。這樣你就不必逃避你模式中的所有/:'〜/(註冊)(?:/ activate /(。{16}))?(?:/(student | teacher | org) )?/?$〜「' –