CodeIgniter Forums
why doesn't this regular expression get recognized by codeigniter's router - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: why doesn't this regular expression get recognized by codeigniter's router (/showthread.php?tid=54777)



why doesn't this regular expression get recognized by codeigniter's router - El Forum - 09-24-2012

[eluser]codeigniterzzz[/eluser]
I have this route:

Code:
$route["((parameter|type|something)-([0-9]+)\/)+"] = 'somecontroller';
so when i test the url with this:

www.somewebsite.com/parameter-1/

codeigniter returns with a page not found error. But I tested the regular expression here:

http://rubular.com/

and it seems to work perfectly fine.

I have also tried putting the leading/trailing /'s:

Code:
$route["/((parameter|type|something)-([0-9]+)\/)+/"] = 'somecontroller';



why doesn't this regular expression get recognized by codeigniter's router - El Forum - 09-24-2012

[eluser]Tống Kiện Phi[/eluser]
you try this code

Code:
$route["((parameter|type|something)-([0-9]+))+"] = 'somecontroller';



why doesn't this regular expression get recognized by codeigniter's router - El Forum - 09-25-2012

[eluser]PhilTem[/eluser]
- is a special character in regexp code. You need to escape it using \ otherwise regexp will interpret it as a spacer defining a range from
parameter OR type OR something to (range from 0 to 9 multiple times)

Maybe try a slightly simpler code
Code:
$route["(parameter\-([0-9]+))"] = 'somecontroller';
which should re-route
parameter-1, paramter-2, ... to somecontroller.
And then add further options on the first part (replace parameter with (parameter|type|something))