【问题标题】:Java Regex to Match URL用于匹配 URL 的 Java 正则表达式
【发布时间】:2022-02-05 16:31:44
【问题描述】:

我需要创建正则表达式来匹配以下形式的 URL

/collected/{deliveryId}/deliverer/{userId}
/customer/{userId}/status/active
/users/{userId}/role

其中delivery-id和user-id是UUID,形式为:124r23452-124234234-123123423534,其他字符串部分是常量。

对于第一个,我尝试了类似的方法但没有奏效:

    String urlRegex = "[a-zA-Z-]*/collected/deliverer/(?=\\S*[-])([a-zA-Z-]+)";

【问题讨论】:

    标签: java regex


    【解决方案1】:

    您可以尝试这种模式:\/collected\/\w{0,9}\/deliverer\/\w{0,} 并使用https://regex101.com/ 网站。这个wikipedia 页面还提供了一些关于正则表达式的详细信息。

    【讨论】:

      猜你喜欢
      • 2012-02-04
      • 2013-03-08
      • 2010-09-14
      • 2019-10-05
      • 1970-01-01
      • 2012-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多