开发者

RegEx to exclude a string

I have the following strings in my application.

/admin/stylesheets/11

/admin/javascripts/11

/contactus

what I want to do is to write a regular expression to capture anything other than string starting with 'admin'

basically my regex should capture only

/contactus

by excluding both

/admin/stylesheets/11

/admin/javascripts/11

to capture all i wrote

/.+/

and i wrote /(admin).+/ which captures everything starts with 'admin'. how can i do the reverse. I mean get everything not starting with 'admin'

thanks in advance

cheers

sa开发者_StackOverflow中文版meera

EDIT - Thanks all for the answers

I'm using ruby/ Rails3 and trying to map a route in my routes.rb file

My original routes file is as followss

match '/:all' => 'page#index', :constraints => { :all => /.+/ }

and i want the RegEx to replace /.+/

thanks


If the language/regular expression implementation you are using supports look-ahead assertions, you can do this:

^/(?!admin/).+/

Otherwise, if you only can use basic syntax, you will need to do something like this:

^/([^a].*|a($|[^d].*|d($|[^m].*|m($|[^i].*|i($|[^n].*)))))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜