字符串(URI)的Regex



我想为字符串组合REGEX:

/maps/basic/5/16/12.png?key=xxx

我在这里试图实现的是,如果字符串(URI(在2个单词后包含3个数字,那么我的条件将为TRUE:

/word/word/number/number/number*

您可以使用以下模式:

^(/[a-zA-Z]+/[a-zA-Z]+/[0-9]+/[0-9]+/[0-9]+)(S.*)$

你的例子的结果是:

  1. 第1组匹配:/maps/basic/5/16/12
  2. 第2组匹配,其余字符串:.png?key=xxx

试试这个:

^/[a-zA-Z]+/[a-zA-Z]+/d+/d+/d+.*

^                 mathes the beginning of the string
/[a-zA-Z]+       matches the first word
/[a-zA-Z]+       matches the second word
/d+/d+/d+   matches the three numbers
.*                matches anything after the numbers

只有当url以两个单词开头,后面跟着三个(或更多(单词以及后面的任何单词时,它才会匹配url。

此处测试:https://regex101.com/r/mjWNUb/1

最新更新