.net core webapi route attribute regex with /

1.3k views Asked by At

I am trying to find a way to match a route when request contains multiple path and URL always end with /end

For example:

domain.com/api/path1/path2/path3/end

domain.com/api/path1/path2/path3/path4/end

I tried [Route("api/{p:regex(([[\\w-]]*\\/){{1,}})}end")] but this didn't work.

Any recommendation?

1

There are 1 answers

0
AudioBubble On

regex pattern must be as below:

^(?:[a-z0-9.]+(\/))*end

Note that in the C# language "\" is the operator character. So you must use \\ instead of \.