将电影名称和年份与电影文件名分开

Seprate movie name and year from moviefile name

我有这样一个文件名

Birdman.2014.DVDSCR.X264-PLAYNOW.mkv

Divergent (2014) 720p Blu-Ray x2649 [Dual-Audio][English DD 5.1 + Hindi DD 5.1] - Mafiaking - TeamTNT ExClusive.mkv

Cradle 2 The Grave 2003 HDTVRip 720p Dual-Audio[Eng+Hindi] ~ BRAR

我必须分开电影名称和年份

获得使用年份perg_match喜欢

$s="Divergent (2014) 720p Blu-Ray x2649 [Dual-Audio][English DD 5.1 + Hindi DD 5.1] - Mafiaking - TeamTNT ExClusive.mkv";
     if (preg_match('/\b\d{4}\b/', $s, $matches)) {
    $year = $matches[0];
}
echo $year;

result :- 2014 //working perfect

但我也想得到像

这样的电影名字

Divergent

Birdman

Cradle 2 The Grave

我也检查这个link

Extracting movie name and year from string were year is optional

但什么也没发生

我怎么得到它?请帮助或提供提示以实现它。

^.+?(?=\s*[(.]?(\d{4}))

你可以尝试 this.The 电影名称将在第一个 group.See 演示中匹配和年份。

https://regex101.com/r/vA0yQ3/2

$re = "/^.+?(?=\s*[(.]?(\d{4}))/mi"; 
$str = "\n\nBirdman.2014.DVDSCR.X264-PLAYNOW.mkv\n\nDivergent (2014) 720p Blu-Ray x2649 [Dual-Audio][English DD 5.1 + Hindi DD 5.1] - Mafiaking - TeamTNT ExClusive.mkv\n\nCradle 2 The Grave 2003 HDTVRip 720p Dual-Audio[Eng+Hindi] ~ BRAR\n"; 

preg_match_all($re, $str, $matches);