我在将这个字符串分割成组件时遇到了困难。我的示例字符串是Criminal.Minds.S10E22.WEB-DL.x264-FUM[ettv]
。我想要将其分割成以下内容:Criminal Minds, 10, 22
。
虽然我稍微尝试过Perl正则表达式,但PHP的实现让我感到困惑。
我已经编写了以下代码:
$word = "Criminal.Minds.S10E22.WEB-DL.x264-FUM[ettv]";
// First replace periods and dashes by spaces
$patterns = array();
$patterns[0] = '/\./';
$patterns[1] = '/-/';
$replacement = ' ';
$word = preg_replace($patterns, $replacement, $word);
print_r(preg_split('#([a-zA-Z])+\sS(\d+)E(\d+)#i', $word));
这将输出 Array ( [0] => Criminal [1] => WEB DL x264 FUM[ettv] )
。请告诉我正确的方向。
?<season>
- Joel G Mathew(?<name>...)
结构是 命名捕获组,允许以更习惯的方式访问您感兴趣的匹配部分。请注意,在存在其他格式的情况下,该模式通常可以通过在(.*?)
和\.\S
之间添加可选消耗模式来进行调整。 - Wiktor Stribiżew