【问题标题】:URL regex without several paths没有多个路径的 URL 正则表达式
【发布时间】:2020-08-12 13:28:17
【问题描述】:

我有 WebMvcConfigurer:

@Configuration
public class MyConfiguration implements WebMvcConfigurer {
    @Override
    public void addViewControllers (ViewControllerRegistry registry) {
        registry.addViewController("/{path:(?!api|res).*}")
            .setViewName("forward:/");
    }
}

我需要将每个请求重定向到 index.html,除了路径 /api/... 和 /res/... 无法创建适当的正则表达式,非常感谢您的帮助。

【问题讨论】:

  • 也许是{path:^(?!(?:api|res)/)}{path:^(?!(?:api|res)/).*}

标签: java regex spring spring-boot


【解决方案1】:
^(?!(\/path\/+|\/res\/+)).*$

如果字符串不以/path//res/ 开头,则此正则表达式匹配。

【讨论】:

    猜你喜欢
    • 2013-11-02
    • 2023-01-23
    • 2012-08-14
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 2020-01-18
    • 2022-08-11
    • 1970-01-01
    相关资源
    最近更新 更多