9

I have a route like so:

routes.MapRoute
    (
    "Profile",
    "profile/{username}",
    new { controller = "Profile", action = "Index" },
    new { username = @"^(getmoreactivity)" }
    );

This works fine for all users but I have a situation where I want to hit an action for getmoreactivity. So I want to make this constraint to say when username is NOT getmoreactivity. It's just not working though.

I've stuck on the RouteDebugger and tried @"[^(getmoreactivity)]" @"^^(getmoreactivity)" @"^getmoreactivity" @"[^getmoreactivity]". Well I've tried countless things but none solve my problem.

How the hell do you put in a NOT constraint on a whole word?

BritishDeveloper
  • 13,219
  • 9
  • 52
  • 62

1 Answers1

20

try:

routes.MapRoute 
( 
"Profile", 
"profile/{username}", 
new { controller = "Profile", action = "Index" }, 
new { username = "(?!getmoreactivity).*" } 
); 

?! is a lookahead: http://www.regular-expressions.info/refadv.html

......

BritishDeveloper
  • 13,219
  • 9
  • 52
  • 62
Lee Gunn
  • 8,417
  • 4
  • 38
  • 33
  • 1
    see also http://stackoverflow.com/questions/406230/regular-expression-to-match-line- that-doesnt-contain-a-word for more details – Simon_Weaver Sep 28 '15 at 01:16