package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?mi)^
# get the title of this movie or series
(?<title>
[-\w'\"]+
# match separator to later replace into correct title
(?<separator> [\s.] )
# note this must be lazy for the engine to work ltr not rtl
(?: [-\w'\"]+\2 )*?
)(?:
# if this is an episode, lets match the season
# number one way or another. if not, the year of the movie
# 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 (?: \2? )? )?
(?<season> \d\d? )
(?: e|x (?:\2? )? )
(?<episode> \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
[(\[]?(?<year>\d{4})[)\]]?
)
|
# optional release name
(?:(?<release> PROPER | REPACK | LIMITED | EXTENDED | INTERNAL | NEW(?:\ SOURCE)? | NUKED | UNRATED | .*?\ EDITION | HC))
|
# optional resolution group
(?<resolution> \d{3,4}\ ?p)
|
# optional quality group
(?<quality> HDTV | WEB[-.]?DL | HDDVD | DVDRip | DVD | B[DR]Rip | Blu[-.\ ]?Ray | HDRip | WEBRIP )
|
# optional codec group
(?<codec> XviD | X26[45] | h26[45] | hevc )
|
# optional audio group
(?<audio> AC3 | AAC | DTS | DD5\.1)
|
# optional team group with hyphen prefix
(?:-(?<team>.*?))?
# optional extension group with . prefix
(?:\.(?<extension>mkv|avi|mp4|srt))?
$`)
var str = `Person.of.Interest.S05E13.HDTV.X264-DIMENSION.mkv
The.Big.Bang.Theory.S09E21.720p.HDTV.X264-DIMENSION[ettv]
The Walking Dead S08E01 Mercy
Brooklyn.Nine-Nine.S03E23.720p.WEBRip.x264
The.Walking.Dead.S07E01.REPACK.720p.HDTV.x265-ShAaNiG
Shame.2011.1080p.BluRay.x265-RARBG
Game.of.Thrones.S04E08.720p.HDTV.x264-KILLERS
The.Grand.Budapest.Hotel.2014.1080p.BluRay.x264-BLOW
Another.Earth.2011.LIMITED.720p.BluRay.X264-AMIABLE
The.Green.Mile.1999.720p.BluRay.x264-HDCLASSiCS
Donnie.Darko.2001.PROPER.1080p.BluRay.x264-RRH
Cosmos.A.Space.Time.Odyssey.S01E12.720p.HDTV.X264-DIMENSION
Game.of.Thrones.S04E10.720p.HDTV.x264-KILLERS
# Will not work with v1 because of the misplaced codec "H264"
Homeland.S05E11.Our.Man.in.Damascus.720p.WEB-DL.DD5.1.H264-NTb[rarbg]
# Will not work with v1 because of the unproperly formatted team name ".rmteam"
limitless.s01e01.pilot.720p.webrip.hevc.x265.rmteam.mkv
Futurama.S06.720p.BluRay.X264-REWARD-SiNNERS
Game.of.Thrones.S04E09.720p.HDTV.x264-KILLERS
# Will not work with v1 because of the misplaced audio coding "DTS"
The Road 2009 Bluray DTS 720 p - TRiNiTY
# Will not work with v1 because of the unexpected "MSubs [DDR]"
Dead Poets Society (1989) 720p Blu-ray x264 DTS MSubs [DDR]
# Will not work anyway because of missing mandatory year
Hot.Fuzz.720p.HDDVD.x264-SEPTiC
True.Detective.S01E01.720p.HDTV.x264-KILLERS
Garden.State.2004.720p.BluRay.X264-AMIABLE
The.Royal.Tenenbaums.2001.1080p.BluRay.X264-AMIABLE
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
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 `
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
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 Golang, please visit: https://golang.org/pkg/regexp/