Seprate movie name and year from moviefile name

假如想象 提交于 2019-12-24 03:48:11

问题


I have a file name like this

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

I have to seperated movie name and year

For getting year in use perg_match like

$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

But I also want to get movie name like

Divergent

Birdman

Cradle 2 The Grave

I also check with this link

Extracting movie name and year from string were year is optional

But nothing happen

How i get it? Please help or provide hint to achive it.


回答1:


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

You can try this.The movie name will be in match and year in the first group.See demo.

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);


来源:https://stackoverflow.com/questions/30369085/seprate-movie-name-and-year-from-moviefile-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!