[英]Codeigniter route not working with regex
I am trying to check if a url is in given format by using regular expression. 我正在尝试使用正则表达式检查网址是否为给定格式。 this is my code. 这是我的代码。
myurl is : example.com/123456-watch-example_video_name myurl是:example.com/123456-watch-example_video_name
$route['([0-9]+)-[watch]-[A-Z0-9_+-]'] = 'mycontroller';
It is going to 404 page. 它将转到404页。 Where I am wrong, i am new to regular expression. 如果我错了,我是新来的正则表达式。
Try the below: 请尝试以下方法:
$route['([0-9]+)-watch-[A-Z0-9_+-]+'] = 'mycontroller';
[watch]
matches one char of watch
, so remove []
, and [A-Z0-9_+-]
matches one char too, for one and more use [A-Z0-9_+-]+
[watch]
相匹配的一个字符watch
,所以删除[]
和[A-Z0-9_+-]
匹配一个字符也为一个多用[A-Z0-9_+-]+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.