I'm working on some routes for my CodeIgniter application, and I need to declare a 'catch-all'/except one regular expression. Any route that doesn't start with 'ajax/' should be redirected to the 'main'-rou开发者_运维技巧ter. Like so:
$route['regexmagichere'] = "main";
So this is definetly way beyond my regex skills and I need some help. The regex should return true on all strings that don't start with 'ajax/', like so:
$string_one = "ajax/someotherstuffhere";
$string_two = " ajax/test";
$string_three = "somestuffhere";
Here $string_one would be the only one returning false. Thanks for your time!
You could try
^((?!ajax).*)
To be litereal to your request. A regexp that returns true for all strings that don't start with ajax/
:
^(?!ajax/).*
You might need to escape the /
as \/
. (?!)
is a negative look-ahead expression explained on this question.
I think ^(?<!ajax)\/
will do the trick.
I stress "think"!
精彩评论