Regex Help! |
[eluser]beaudierman[/eluser]
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: Code: $route['^\d{3}-(.*)$'] = 'product/index/$1'; I've also tried: Code: $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.
[eluser]Matalina[/eluser]
did you try to take out the start ^ and end $ characters?
[eluser]Matalina[/eluser]
here's another method... [0-9]{3}-(.*) if that doesn't work escape the -
[eluser]beaudierman[/eluser]
[quote author="Matalina" date="1340744105"]here's another method... [0-9]{3}-(.*) if that doesn't work escape the -[/quote] Aha! It worked but was then only bringing in the Code: (.*)
[eluser]Matalina[/eluser]
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 123- I would use [0-9]{3}-.+
[eluser]InsiteFX[/eluser]
Here is another Regex tester Look at the bottom right and you can download a Windows desktop version of it. |
Welcome Guest, Not a member yet? Register Sign In |