Welcome Guest, Not a member yet? Register   Sign In
route regulaur expression
#1

[eluser]ovulator[/eluser]
I am trying to rempap a uri using a regular expression.

I want it so that if someone goes to example.com/product/1111x11
they will be redirected to example.com/product/number/1111x11

All I need to make sure is that the first four characters are digits so I used this

Code:
$route['product/(^\d{4})'] = 'product/number/$1';

Which is not working. I know that the regular expression: ^\d{4} works for what I want it to do, but it isn't working here. I just get a 404 error. I tried
Code:
$route['product/(\d+)'] = 'product/number/$1';
Which works if the product is only numbers, but some have letters after the fourth digit, so it doesn't work for the. Any help?
#2

[eluser]ovulator[/eluser]
Hmm, this works:

Code:
$route['product/(\d{4}(:any)?)'] = 'product/number/$1';

But I still don't understand why my initial regular expression didn't work.
#3

[eluser]ovulator[/eluser]
Oh geez, never mind. I guess I don't understand how the carot works in regular expressions. X|




Theme © iAndrew 2016 - Forum software by © MyBB