正则表达式不匹配字符串的多个部分

时间:2015-01-09 21:41:56

标签: regex

我想写正则表达式,如

  

/调度/组/成员/ [列表* |得到* |搜索*] JSON

应与字符串

匹配

/scheduling/groups/list.json

/scheduling/groups/getGroup.json

/scheduling/groups/searchMember.json

且不应与

匹配
  

/scheduling/groups/save.json

2 个答案:

答案 0 :(得分:1)

您可以使用此正则表达式

\/scheduling\/groups\/(?:list|get|search).*\.json

Online demo

答案 1 :(得分:1)

甚至可以使用像

这样的东西
 # (?i)/scheduling/groups/(?:list|get|search)[^/]*\.json

 (?i)                          # Case insensitive modifier
 /scheduling/groups/           # Literal '/scheduling/groups/'
 (?:                           # Cluster group, one of either 
      list                          # 'list'
   |                              # or,
      get                           # 'get'
   |                              # or,
      search                        # 'search'
 )                             # End cluster group
 [^/]*                         # 0 - many characters that are non filename separators
 \. json                       # to get to '.jason'