• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex Help!

I'm trying to set up a custom 404 page using the 404_override option. Trouble is, I have a route set up as (:any) which apparently completely breaks 404_override. If I remove the (:any) rule, it works fine. So, I need to eliminate my (:any) call and instead be specific about what I want for that rule, the problem is that regex doesn't seem to work very well.

Basically I just need to match 3 digits, followed by a dash, then anything.

What I have:
$route['^\d{3}-(.*)$'] = 'product/index/$1';

I've also tried:
$route['(:num)-(:any)'] = 'product/index/$1';

Which works great on regexpal, but, not on CI. My regex is very rusty so if anyone has any suggestions I'd greatly appreciate it.

did you try to take out the start ^ and end $ characters?

Yes I have.

here's another method...


if that doesn't work escape the -

[quote author="Matalina" date="1340744105"]here's another method...


if that doesn't work escape the -[/quote]

Aha! It worked but was then only bringing in the
half of my query string. I changed the $1 to $0 and all works! Thank you!

it is only bringing in the second half because of the parenthesis.

([0-9]{3}-.*) should allow $1 to be used but it would be the same as $0 anyway.

http://myregextester.com/ will show you what information falls into what part of the array.

and unless you plan on having a uri that looks like


I would use [0-9]{3}-.+

Here is another Regex tester

Look at the bottom right and you can download a Windows desktop version of it.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.