You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用PowerShell从剧集标题中提取季集编号,修复误匹配问题

PowerShell 剧集季集编号提取修复方案

问题根源

原有代码单独匹配季、集标识,未做关联校验,导致孤立的E + 数字类内容会被误识别为有效集数。

修复后代码

# 统一匹配完整季集组合,不区分大小写
$seasonEpisodePattern = '(?:(?:S(?:eason)?\s*(\d+))\s*(?:E(?:pisode)?\s*(\d+))|(\d+)\s*x\s*(\d+))'
$matchResult = $title | Select-String -Pattern $seasonEpisodePattern -CaseSensitive:$false

$season = $null
$episode = $null
if ($matchResult) {
    $groups = $matchResult.Matches.Groups
    # S/Season + E/Episode 格式匹配结果
    if ($groups[1].Success) {
        $season = $groups[1].Value
        $episode = $groups[2].Value
    }
    # 数字x数字格式匹配结果
    else {
        $season = $groups[3].Value
        $episode = $groups[4].Value
    }
}

兼容格式说明

完美覆盖要求的所有合法季集格式:

  • xxx S01E01
  • xxxe 1 S01E01(前缀孤立e 1不会被误识别)
  • xxx S01 E01
  • xxx 01x01
  • xxx Season 01 Episode 01

校验规则

只要标题中没有符合要求的完整季集组合,$season和$episode都会保持空值,类似xxxxxE 1这类无效内容不会触发任何匹配。

内容的提问来源于stack exchange,提问作者maj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 20:54:03