2011-06-09 58 views
0

我設立一個Zend_Route(但它仍然只是一個正則表達式),我希望匹配的URL像簡單的PHP正則表達式

/en/experience/this-is-my-name-and-the-last-is-1-of-id-123456.html 

所以我想抓住

this-is-my-name-and-the-last-is-1-of 

和在

123456 

我試圖

\w{2}/experience/(.+)?-(\d+)\.html 

但這似乎並不奏效。

如果相反,例如如果是ID名稱

/en/experience/123456-this-is-my-name-and-the-last-is-1-of-id.html 

我可以用

\w{2}/experience/(\d+)-(.+)\.html 

但是,這是一個警察了 - 等如何搭配原始格式什麼建議嗎?

+1

你的正則表達式適合我:http://www.rubular.com/r/Ou5N48bV2Q – codaddict 2011-06-09 12:35:36

+0

所以你不想匹配'-id -'位?你的例子沒有顯示它 – Eric 2011-06-09 12:38:01

回答

1

試試這個:

/\w{2}/experience/(.+?)-(\d+)\.html 
+0

完美!非常感謝 – Xrender 2011-06-09 12:58:48

0

試試這個:
/\w{2}/experience/(.+)?-(\d+)\.html

Zend的路線內做到這一點:
preg_match('#^/\w{2}/experience/(.+)?-(\d+)\.html$#i', '/en/experience/this-is-my-name-and-the-last-is-1-of-id-123456.html', $matches);

所以,你的模式只能用在開始斜線相匹配。