Spring @RequestMapping “Not Contains” Regex

后端 未结 2 725
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-23 07:02

I have this RequestMapping:

@RequestMapping(value = \"/route/to-{destination}-from-{departure}.html\", method = {RequestMethod.GET, RequestMethod.HEAD})
<         


        
相关标签:
2条回答
  • 2021-01-23 07:16

    You may use

    "/route/to-{destination:(?!.*-from-).+}.html"
    

    The ^ anchor would search for the start of the string and will fail any match here.

    The (?!.*-from-) negative lookahead will fail any input that contains -from- after any 0+ chars other than line break chars.

    The .+ pattern will consume all 1 or more chars other than line break chars to the end of the line.

    0 讨论(0)
  • 2021-01-23 07:34

    try using this :->

    {destination:^(?!from)+}

    or

    {destination:^((?!-from-).)+}

    0 讨论(0)
提交回复
热议问题