问题
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