2014-03-07 23 views
0

我想通過使用正則表達式來檢查URL是否在給定的格式。這是我的代碼。Codeigniter路由不能與正則表達式

myurl是:example.com/123456-watch-example_video_name

$route['([0-9]+)-[watch]-[A-Z0-9_+-]'] = 'mycontroller'; 

這是要404頁。 我錯了,我是新來的正則表達式。

+0

嘗試刪除'['字符[watch]',就像這樣:'([0-9] +) - watch- [A-Z0-9 _ + - ]' – TrungDQ

回答

1

嘗試以下:

$route['([0-9]+)-watch-[A-Z0-9_+-]+'] = 'mycontroller'; 

[watch]比賽watch一個字符,因此將其刪除[][A-Z0-9_+-]匹配一個字符也爲一個在`更多使用[A-Z0-9_+-]+

+0

感謝它的完美工作 –