$re = '/^
# get the title of this movie or series
(?P<title>
[-\w\'\"]+
# match separator to later replace into correct title
(?P<separator> [ .] )
# note this *must* be lazy for the engine to work ltr not rtl
(?: [-\w\'\"]+\2 )*?
)
# start of movie vs serie check
(?:
# if this is an episode, lets match the season
# number one way or another. if not, the year
# of the movie
(?:
# series. can be a lot prettier if we used perl regex...
# make sure this is not just a number in the title followed by our separator.
# like, iron man 3 2013 or my.fictional.24.series
(?! \d+ \2 )
# now try to match the season number
(?: s (?: eason \2? )? )?
(?P<season> \d\d? )
# needed to validate the last token is a dot, or whatever.
(?: e\d\d? (?:-e?\d\d?)? | x\d\d? )? |
# this is likely a movie, match the year
(?P<year> [(\]]?\d{4}[)\]]? )
)
# make sure this ends with the separator, otherwise we
# might be in the middle of something like "1080p"
(?=\2) |
# if we get here, this is likely still a movie.
# match until one of the keywords
(?= BOXSET | XVID | DIVX | LIMITED |
UNRATED | PROPER | DTS | AC3 | AAC | BLU[ -]?RAY |
HD(?:TV|DVD) | (?:DVD|B[DR]|WEB)RIP | \d+p |Â [hx]\.?264
)
)/imx';
$str = 'the.black.adder.3x01.dish.and.dishonesty.dvdrip.xvid-dvdiso.avi
the.black.adder.3x02.ink.and.incapability.dvdrip.xvid-dvdiso.avi
the.black.adder.3x03.nob.and.nobility.dvdrip.xvid-dvdiso.avi
the.black.adder.3x04.sense.and.senility.dvdrip.xvid-dvdiso.avi
the.black.adder.3x05.amy.and.amiability.dvdrip.xvid-dvdiso.avi
the.black.adder.3x06.duel.and.duality.dvdrip.xvid-dvdiso.avi
Game.of.Thrones.S04E08.720p.HDTV.x264-KILLERS
Futurama.S06.720p.BluRay.X264-REWARD-SiNNERS
The.Grand.Budapest.Hotel.2014.1080p.BluRay.x264-BLOW
Another.Earth.2011.LIMITED.720p.BluRay.X264-AMIABLE
Game.of.Thrones.S04E09.720p.HDTV.x264-KILLERS
The.Green.Mile.1999.720p.BluRay.x264-HDCLASSiCS
Cosmos.A.Space.Time.Odyssey.S01E12.720p.HDTV.X264-DIMENSION
Game.of.Thrones.S04E10.720p.HDTV.x264-KILLERS
The Road 2009 Bluray DTS 720 p - TRiNiTY
Dead Poets Society (1989) 720p Blu-ray x264 DTS MSubs [DDR]
Garden.State.2004.720p.BluRay.X264-AMIABLE
The.Royal.Tenenbaums.2001.1080p.BluRay.X264-AMIABLE
Donnie.Darko.2001.1080p.PROPER.BluRay.x264-RRH
Hot.Fuzz.720p.HDDVD.x264-SEPTiC
True.Detective.S01E01.720p.HDTV.x264-KILLERS
Eternal Sunshine of the Spotless Mind 2004 DiVERSiTY
Non-Stop.2014.720p.BluRay.X264-AMIABLE
True.Detective.S01E02.720p.HDTV.x264-KILLERS
Fargo.S01E07.720p.HDTV.X264-DIMENSION
Silicon.Valley.S01E08.720p.HDTV.x264-KILLERS
True.Detective.S01E03.720p.HDTV.x264-KILLERS
Fargo.S01E08.720p.HDTV.X264-DIMENSION
Suits.S04E01.720p.HDTV.X264-DIMENSION
True.Detective.S01E04.720p.HDTV.x264-KILLERS
Fargo.S01E10.720p.HDTV.X264-DIMENSION
Suits.S04E02.720p.HDTV.X264-DIMENSION
True.Detective.S01E06.720p.HDTV.x264-2HD
The.Descendants.2011.720p.BluRay.x264-ALLiANCE
True.Detective.S01E07.720p.HDTV.x264-KILLERS
Killing Season 2013 DVDRip x264-NoRBiT
Game of Thrones S04E10 720p HDTV x264-KILLERS
Game of Thrones S04E09 720p HDTV x264-KILLERS
Game of Thrones S04E08 720p HDTV x264-KILLERS
Game of Thrones S04E07 720p HDTV x264-KILLERS
Game of Thrones S04E05 720p HDTV x264-KILLERS
Game of Thrones S04E03 720p HDTV x264-KILLERS
Game of Thrones S04E04 720p HDTV x264-KILLERS
Game of Thrones S04E01 720p HDTV x264-KILLERS
Game of Thrones S04E02 720p HDTV x264-2HD
Game of Thrones S04E06 720p HDTV x264-DIMENSION
Game of Thrones S04E10 HDTV x264-KILLERS
Watch Dogs-RELOADED
True Blood S07E01 720p HDTV x264-KILLERS
Non-Stop 2014 720p BluRay X264-AMIABLE
The Big Bang Theory S07E24 720p HDTV X264-DIMENSION
Game of Thrones S04E09 HDTV x264-KILLERS
24 S09E09 720p HDTV X264-DIMENSION
The Big Bang Theory S07E23 720p HDTV X264-DIMENSION
Game of Thrones S04E08 HDTV x264-KILLERS
Suits S04E02 720p HDTV X264-DIMENSION
Game of Thrones S04E06 INTERNAL 720p HDTV x264-BATV
The Big Bang Theory S07E22 720p HDTV X264-DIMENSION
Suits S04E01 720p HDTV X264-DIMENSION
Watch Dogs Hotfix-RELOADED
Wolfenstein The New Order-RELOADED
The Big Bang Theory S07E20 720p HDTV X264-DIMENSION
The Big Bang Theory S07E21 720p HDTV X264-DIMENSION
Suits S04E03 720p HDTV X264-DIMENSION
Californication S07E10 720p HDTV x264-DAA
True Blood S07E01 HDTV x264-KILLERS
24 S09E08 720p HDTV X264-DIMENSION
Game of Thrones S04E07 HDTV x264-KILLERS
Game of Thrones S04E05 HDTV x264-KILLERS
Silicon Valley S01E01 720p HDTV x264-KILLERS
Game of Thrones S04E06 HDTV x264-KILLERS
24 S09E07 720p HDTV X264-DIMENSION
Californication S07E08 720p HDTV x264-DAA
The Big Bang Theory S07E19 720p HDTV X264-DIMENSION
24 S09E06 720p HDTV X264-DIMENSION
Californication S07E11 720p HDTV x264-KILLERS
The Wolf of Wall Street 2013 DVDScr x264-HaM
Game of Thrones S04E01 HDTV x264-KILLERS
Game of Thrones S04E10 1080p HDTV x264-BATV
The Wolf of Wall Street 2013 720p BluRay X264-AMIABLE
Game of Thrones S04E02 HDTV x264-2HD
Game of Thrones S04E03 HDTV x264-KILLERS
The Big Bang Theory S07E24 HDTV x264-LOL
24 S09E05 720p HDTV X264-DIMENSION
Southpark Stick Of Truth-RELOADED
300 Rise Of An Empire 2014 720p BluRay x264-BLOW
Californication S07E09 INTERNAL 720p HDTV x264-BATV
The Monuments Men 2014 720p BluRay x264-BLOW
The Big Bang Theory S07E18 720p HDTV X264-DIMENSION
Suits S04E01 HDTV x264-LOL
The Wolf Of Wall Street 2013 720p BRRip x264 AAC-ViSiON
Her 2013 720p BluRay x264-SPARKS
The Big Bang Theory S07E17 720p HDTV X264-DIMENSION
The Big Bang Theory S07E23 HDTV x264-LOL
Family Guy S12E20 720p HDTV X264-DIMENSION
The Walking Dead S04E15 720p HDTV x264-2HD
300 Rise Of An Empire 2014 1080p BluRay x264-BLOW
24 S09E04 720p HDTV X264-DIMENSION
The Big Bang Theory S07E16 720p HDTV X264-DIMENSION
Californication S07E07 720p HDTV x264-DAA
Suits S04E02 HDTV x264-LOL
Snowpiercer 2013 BRRip XviD AC3-AQOS
Fargo S01E09 720p HDTV X264-DIMENSION
Fargo S01E10 720p HDTV X264-DIMENSION
Silicon Valley S01E08 720p HDTV x264-KILLERS
The Walking Dead S04E12 720p HDTV x264-REMARKABLE
Falling Skies S04E01 720p HDTV x264-KILLERS
The Big Bang Theory S07E22 HDTV x264-LOL
The Hobbit The Desolation of Smaug 2013 1080p BluRay x264-SPARKS
Thor The Dark World 2013 720p HDRip XviD-AQOS
Silicon Valley S01E02 720p HDTV x264-2HD
Californication S07E06 720p HDTV x264-DAA
True Detective S01E01 720p HDTV x264-KILLERS
The Walking Dead S04E13 720p HDTV x264-2HD
Robocop 2014 720p BluRay x264-SPARKS
The Walking Dead S04E16 PROPER 720p HDTV x264-KILLERS
The Big Bang Theory S07E21 HDTV x264-LOL
The Grand Budapest Hotel 2014 720p BluRay x264-BLOW
24 S09E03 720p HDTV X264-DIMENSION
True Detective S01E03 720p HDTV x264-KILLERS
Game of Thrones S04E04 REPACK HDTV x264-KILLERS
24 S09E01 720p HDTV X264-DIMENSION
24 S09E02 720p HDTV X264-DIMENSION
Silicon Valley S01E03 720p HDTV x264-KILLERS
The Big Bang Theory S07E15 720p HDTV X264-DIMENSION
Dallas Buyers Club 2013 720p BRRip x264 AAC-ViSiON
The Walking Dead S04E11 720p HDTV x264-2HD
How I Met Your Mother S09E23-E24 720p HDTV x264-REMARKABLE
Suits S03E16 720p HDTV x264-KILLERS
GRID Autosport-RELOADED
Silicon Valley S01E05 720p HDTV x264-KILLERS
Vikings S02E10 720p HDTV x264-2HD
Silicon Valley S01E06 720p HDTV x264-2HD
300 Rise Of An Empire 2014 720p BRRiP XViD AC3-LEGi0N
Californication S07E05 720p HDTV x264-2HD
Silicon Valley S01E04 720p HDTV x264-KILLERS
The Wolf Of Wall Street 2013 720p BRRip x264 AAC-ViSiON
Snowpiercer 2013 BRRip XviD AC3-AQOS
Dallas Buyers Club 2013 720p BRRip x264 AAC-ViSiON
300 Rise Of An Empire 2014 720p BRRiP XViD AC3-LEGi0N
American Hustle 2013 720p BRRip x264 AAC-ViSiON
The Grand Budapest Hotel 2014 720p BRRiP XViD AC3-LEGi0N
This Is The End 2013 720p BRRip x264 AAC-ViSiON
Non-Stop 2014 720p BRRiP XViD AC3-LEGi0N
A Million Ways To Die In The West 2014 720p New Webrip x264 AC3 TiTAN
Captain Phillips 2013 720p BRRip x264 AAC-ViSiON
The Lego Movie 2014 720p HDRip XviD-AQOS
Now You See Me 2013 EXTENDED 720p BDRip x264 AAC-ViSiON
Bad Neighbours 2014 720p WEBRIP x264 AC3-EVE
Gravity 2013 720p WEBRiP XViD AC3-LEGi0N
The Raid 2 2014 720p BRRiP XViD AC3-LEGi0N
Under The Skin 2013 720p HDRIP x264 AC3 TiTAN
The Hobbit The Desolation Of Smaug 2013 720p BRRip x264 AAC-ViSiON
The Wolverine 2013 EXTENDED 720p BRRip x264 AAC-ViSiON
Pompeii 2014 720p BRRiP XViD AC3-LEGi0N
12 Years A Slave 2013 720p BDRip XviD AC3-ViSiON
Frozen 2013 720p BRRip x264 AAC-ViSiON
Man Of Steel 2013 720p BRRip x264 AAC-ViSiON
Elysium 2013 720p WEBRiP XViD AC3-LEGi0N
The Monuments Men 2014 720p BRRiP XViD AC3-LEGi0N
Snowpiercer 2013 720p BDRip x264 AAC-ViSiON
The Hunger Games Catching Fire 2013 IMAX EDITION 720p BRRip XviD AC3-ViSiON
Robocop 2014 720p BRRiP XViD AC3-LEGi0N
Jack Ryan Shadow Recruit 2014 720p BRRiP XViD AC3-LEGi0N
Bad Words 2013 720p BRRiP XViD AC3-LEGi0N
The Double 2014 720p HDRip x264 AAC-FooKaS
Prisoners 2013 720p WEB-DL x264 AAC-ViSiON
The Secret Life Of Walter Mitty 2013 720p BRRip x264 AAC-ViSiON
Riddick 2013 UNRATED DC 720p WEB-DL XviD AC3-ELiTE
47 Ronin 2013 720p WEB-DL XviD AC3-ELiTE
Enders Game 2013 720p BRRiP XViD AC3-LEGi0N
Oblivion 2013 720p BRRip x264 AAC-ViSiON
That Awkward Moment 2014 720p BRRiP XViD AC3-LEGi0N
The Raid 2 2014 BDRip x264-GECKOS
47 Ronin 2013 720p BRRip x264 AAC-ViSiON
The Grand Budapest Hotel 2014 720p WEBRIP x264 AC3-EVE
Her 2013 720p BRRiP XViD AC3-LEGi0N
Don Jon 2013 720p BRRip x264 AAC-ViSiON
3 Days to Kill 2014 EXTENDED 720p BRRiP XViD AC3-LEGi0N
The Lego Movie PROPER 720p HDRIP x264 AC3 TiTAN
Thor The Dark World 2013 720p WEBRiP XViD AC3-LEGi0N
White House Down 2013 720p BRRip x264 AAC-ViSiON
The Hunger Games Catching Fire 2013 IMAX EDITION 720p BRRip x264 AAC-ViSiON
The Lego Movie 2014 720p BRRiP XViD AC3-LEGi0N
Bad Grandpa 2013 UNRATED 720p WEB-DL XviD AC3-ELiTE
Non-Stop 2014 BRRip XviD AC3-SANTi
Escape Plan 2013 720p BRRip x264 AAC-ViSiON
Despicable Me 2 2013 720p BRRip x264 AAC-ViSiON
Delivery Man 2013 720p BRRiP XViD AC3-LEGi0N
Blended 2014 720p WEBRIP x264 AC3-EVE
RoboCop 2014 720p WEBRIP x264 AC3-EVE
The Great Gatsby 2013 720p BRRip x264 AAC-ViSiON
Fast And Furious 6 2013 720p WEBRiP XViD AC3-LEGi0N
A Million Ways to Die in the West 2014 HC 720p WEBRIP x264 AC3-MiLLENiUM
Red 2 2013 720p BRRip x264 AAC-ViSiON
The Lone Ranger 2013 720p BDRip x264 AAC-ViSiON
World War Z 2013 UNRATED 720p BRRiP XViD AC3-LEGi0N
Enemy 2013 LIMITED 720p BRRiP XViD AC3-LEGi0N
Vampire Academy 2014 720p BRRiP XViD AC3-LEGi0N
The Legend Of Hercules 2014 720p BRRip x264 AAC-ViSiON
Non-Stop 2014 BDRip X264-AMIABLE
Afflicted 2013 LIMITED 720p BRRiP XViD AC3-LEGi0N
Street Fighter Assassin\'s Fist 2014 720p HDRip x264 AC3 TiTAN
Veronica Mars 2014 HDRip AC3 XviD-EVO
2 Guns 2013 720p BRRip x264 AAC-ViSiON
Anchorman 2 The Legend Continues 2013 UNRATED 720p BRRip x264 AAC-ViSiON
Lone Survivor 2013 720p WEBRiP XVID AC3-MAJESTIC
Kick-Ass 2 2013 720p BRRip x264 AAC-ViSiON
Jack Ryan Shadow Recruit 2014 HDRip XviD AC3-EVO
Rush 2013 720p BRRip x264 AAC-ViSiON (Happy New Year from ViSiON!)
Calvary 2014 720p BRRiP XViD AC3-LEGi0N
The Hunger Games Catching Fire 2013 BRRip XviD AC3-SANTi
Jack Ryan Shadow Recruit 2014 720p WEBRIP x264 AC3-EVE
Thor The Dark World 2013 720p BRRip x264 AAC-ViSiON
Bad Neighbours 2014 WEBRip NEW SOURCE Xvid Mp3 MiLLENiUM
Prisoners 2013 720p BRRiP x264 AC3-LEGi0N
Elysium 2013 720p BRRip x264 AAC-ViSiON
Pacific Rim 2013 720p BRRip x264 AAC-ViSiON
Saving Mr Banks 2013 720p BRRip x264 AAC-ViSiON
The Monuments Men 2014 BDRip x264-COCAIN
Joe 2013 1080p WEBRIP x264 AC3-EVE
I Frankenstein 2014 720p BRRiP XViD AC3-LEGi0N
The Secret Life Of Walter Mitty 2013 720p WEB-DL XviD AC3-ELiTE
The Monuments Men 2014 BRRip XviD AC3-AQOS
About Time 2013 720p BDRip XviD AC3-ELiTE
Frozen 2013 720p BRRiP XViD AC3-LEGi0N
Enemy 2013 720p WEBRiP XViD AC3-LEGi0N
I Frankenstein 2014 BRRip XviD AC3-SANTi
Out Of The Furnace 2013 720p BRRip x264 AAC-ViSiON
Walk of Shame 2014 LIMITED 720p BRRiP XViD AC3-LEGi0N
Iron Man 3 2013 720p BDRip x264 AAC-ViSiON
The Monuments Men 2014 720p BDRIP x264 AC3-EVE
Anchorman 2 The Legend Continues 2013 720p HDRIP x264 AC3 TiTAN
Captain Phillips 2013 720p BRRiP XViD AC3-LEGi0N
Jack Ryan Shadow Recruit 2014 BRRip XviD AC3-SANTi
Cloudy With A Chance Of Meatballs 2 2013 720p BRRip x264 AAC-ViSiON
my.fictional.24.series.s01e02.720p-firas ';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php