This question follows on from a previous question about If-Then-Else Regular Expressions.
Because of how I phrased my problem in the other question solutions didn't use the (?(A)X|Y) syntax. But I think I need to use that approach.
Here is my problem re-phrased...
I need a regex that takes as input a string representing a filename.
Here are my test strings...
The Edge Of Seventeen 2016 720p.mp4
20180511 2314 - Film4 - Northern Soul.ts
20150526 2059 - BBC Four - We Need to Talk About Kevin.ts
If the filename matches this regex:
\d{8} \d{4} -.*?- .*?\.ts
Then this RegEx should be applied:
\d{8} \d{4} -.*?- ?(.*)\.ts
If the filename does not match that first regex then this regex should be applied to it:
(.*[^ _\,\.\(\)\[\]\-])[ _\.\(\)\[\]\-]+(19[0-9][0-9]|20[0-9][0-9])([ _\,\.\(\)\[\]\-]|[^0-9]$)?
This is the expected output...
Test string:
The Edge Of Seventeen 2016 720p.mp4
Expected output:
"The Edge Of Seventeen 2016 " (quotes only included to show that a trailing space can be left at the end)
Test String:
20180511 2314 - Film4 - Northern Soul.ts
Expected output:
Northern Soul
Test String:
20150526 2059 - BBC Four - We Need to Talk About Kevin.ts
Expected output:
We Need to Talk About Kevin
Here is what I have tried to make the If-Then-Else Regex but it doesn't work:
I use this format --> (?(A)X|Y)
(?(\d{8} \d{4} -.*?- .*?\.ts)\d{8} \d{4} -.*?- ?(.*)\.ts|(.*[^ _\,\.\(\)\[\]\-])[ _\.\(\)\[\]\-]+(19[0-9][0-9]|20[0-9][0-9])([ _\,\.\(\)\[\]\-]|[^0-9]$)?)
This is A
\d{8} \d{4} -.*?- .*?\.ts
This is X
\d{8} \d{4} -.*?- ?(.*)\.ts
This is Y
(.*[^ _\,\.\(\)\[\]\-])[ _\.\(\)\[\]\-]+(19[0-9][0-9]|20[0-9][0-9])([ _\,\.\(\)\[\]\-]|[^0-9]$)?
I have tested the A, X and Y Regexes and they work individually but not when I put them together. Can someone help to piece them together using PCRE standard?
Cheers,
Flex
\d{8} \d{4} -.*?- ?(.*)\.ts|(.*[^] _,.()[-])[] _.()[-]+(19[0-9][0-9]|20[0-9][0-9])([] _,.()[-]|[^0-9]$)?^\d{8} \d{4} -.*?- ?\K.*(?=\.ts$)|^.*[^][ _,.()-][][ _.()-]+(?:19|20)\d{2}(?!\d)