Arvind Kumar
Arvind Kumar

Reputation: 609

URL Matcher in spring boot with regular expression

I have requirement to handle all request except few with single handler method in spring boot.

The valid urls that should be serveed -

/test/login
/test/dashboard
/test/validate/details

and the invalid urls that should not be served is -

/test/asset/login
/test/asset
/test/validate/asset

basically any URL which contains string "asset" should not be handled.

So far I am trying it as follows but it's not working -

@GetMapping("test/{path:^(?!.*(asset))}")
    String hello(String path){
        return "hello>>" + path;
    }

But this is not working. I think there is some problem with the regex that I am using.

Any help is much appreciated.

Upvotes: 0

Views: 3006

Answers (1)

rotemp
rotemp

Reputation: 61

Try this regex:

^(?:(?!asset).)*$

Upvotes: 2

Related Questions