Seprate movie title and year of movie title

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] - Mafia - TeamTNT ExClusive.mkv

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

I need to separate the movie name and year

Per year of using perg_match, for example

$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 // works fine

But I also want to get the name of the movie, for example

diverging

Birdman

Cradle 2 Grave

I also check this link

Retrieving the movie name and year from the string was valid optional

But nothing happens

As I understand? Please help or give us a hint.

+2
source share
1 answer
 ^.+?(?=\s*[(.]?(\d{4})) 

You can try this. The name of the film will be in the match and year in the first group. Watch the 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); 
+3
source

Source: https://habr.com/ru/post/1240299/


All Articles