0

I need to extract a movie name from a filename like these...

Filename: 20150813 2159 - NBC +1 - Prometheus.ts
Movie Name: Prometheus

Filename: 20150831 2159 - CBS+1 - The Bourne Identity.ts
Movie Name: The Bourne Identity

Filenames are always formatted like: "A - B - C" where A is a date, B is a TV channel and C is the movie name.
The movie name might have spaces in it and possibly also the "-" character but "hopefully" not a "- " substring.

Example Strategy:

  1. The filename must end with a .ts
  2. Search from the end of the filename starting from the first character to the left of the .ts
  3. Working backwards (right to left) capture all the text up until the first character that is to the right of a "- " substring.

What is the Regex to do this please?

Cheers,

Flex

FlexMcMurphy
  • 332
  • 4
  • 14
  • 1
    https://regex101.com/r/gT8wK5/1331 – Eraklon Feb 23 '20 at 13:47
  • Thanks Eraklon! I want to use this Regex in a Kodi Scraper https://kodi.wiki/view/Scrapers#.3CRegExp.3E.3Cexpression.3E.3C.2FRegExp.3E Using your solution will the movie name be available in \1 like this --> output="
    \1
    "
    – FlexMcMurphy Feb 23 '20 at 14:16
  • 1
    It should I guess. At least in most regex engines thats the way to reference it or $1 – Eraklon Feb 23 '20 at 14:25
  • 1
    I think it was unfair to down vote my question. Wiktor linked me to a large and complicated post that is basically yet another encyclopedia about the Rules of Regular Expressions about which there are already thousands of resources on the web. I spent hours already trying to make sense of them, for amateur coders like me they are just too hard to understand. What is the point of sites like Stackoverflow if I can't ask for specific help? My question was very clear and may benefit others, – FlexMcMurphy Feb 23 '20 at 16:11
  • 1
    I gave you an upvote to compensate it. I mostly agree with you. – Eraklon Feb 23 '20 at 16:14
  • Actually Eraklon.. I am trying to use your Regex with Kodi and it doesn't work there. I think the "Full Match" has to be the movie name. Can you help me tweak your regex https://regex101.com/r/gT8wK5/1331 so the Full Match is (e.g: Prometheus) rather than Group 1. Cheers. – FlexMcMurphy Mar 02 '20 at 22:41
  • 1
    Maybe this https://regex101.com/r/gT8wK5/1339. – Eraklon Mar 03 '20 at 09:05

0 Answers0