正则表达式 - 最初停止匹配

时间:2015-09-23 09:24:27

标签: regex match television

我试图通过正则表达式匹配电视节目名称。我发现this answer为我提供了良好的匹配基础。 但这还不够。我还需要匹配像

这样的东西
foo - 1x01

我设法解决了它添加“ - ”作为转义字符和新格式的新控件:

^(
  (?P<ShowNameA>.*[^ (_.-]) # Show name
    [ (_.-]+
    ( # Year with possible Season and Episode
      (?P<ShowYearA>\d{4})
      ([ (_.]+S(?P<SeasonA>\d{1,2})E(?P<EpisodeA>\d{1,2}))?
    | # Season and Episode only
      (?<!\d{4}[ (_.])
      S(?P<SeasonB>\d{1,2})E(?P<EpisodeB>\d{1,2})
    | # Year with possible Season and Episode f2
      (?P<ShowYearB>\d{4})
      ([ (_.]+(?P<SeasonC>\d{1,2})x(?P<EpisodeC>\d{1,2}))?
    | # Season and Episode only f2
      (?<!\d{4}[ (_.])
      (?P<SeasonD>\d{1,2})x(?P<EpisodeD>\d{1,2})
    | # Alternate format for episode
      (?P<EpisodeE>\d{3})
    )
|
  # Show name with no other information
  (?P<ShowNameB>.+)
)

但我注意到一个更大的问题。如果我用

之类的东西测试它
foo - 1x01 - 720p
foo - 1x01 - 1080p

即使之前有比赛,它也会将720识别为episodeD而将1080p识别为YearA。如何更改正则表达式以在第一场比赛时停止? 这是我编辑的正则表达式 https://regex101.com/r/mR6oD4/16

0 个答案:

没有答案