[kwlug-disc] Regular Expression to Match Movie Titles and Year and Ignore the rest.

Sean D thornlord at gmail.com
Tue Dec 31 11:37:51 EST 2024


I am a fan of RegEx but not even close to an expert.

The following expression is supposed to provide what you need:

^([^.]+(?:\.[^.]+)*)\.(\d{4})\.

Here's a breakdown of the regular expression:

^ asserts the position at the start of the string.
([^.]+(?:\.[^.]+)*) captures the title. It matches one or more characters
that are not a dot ([^.]+), followed by zero or more groups of a dot and
one or more characters that are not a dot ((?:\.[^.]+)*).
\. matches a literal dot.
(\d{4}) captures the year. It matches exactly four digits.
\. matches another literal dot.

---


110.  Labour to keep alive in your breast that little celestial fire called
conscience.
--George Washington


On Tue, Dec 31, 2024 at 11:29 AM John Driezen <jdriezen at sympatico.ca> wrote:

> Can anyone give me a regular expression to turn the following filename
>
>   "Zero.Dark.Thirty.2012.720p.BrRip.x264.BOKUTOX.YIFY.mp4"
>
> into
>
> "Zero Dark Thirty (2012)-720p.mp4"
>
> 201[0-9] matches the year
>
> How do I match the title before the year, and ignore everything after
> the ".720p"?
>
> John Driezen
>
>
>
> _______________________________________________
> kwlug-disc mailing list
> To unsubscribe, send an email to kwlug-disc-leave at kwlug.org
> with the subject "unsubscribe", or email
> kwlug-disc-owner at kwlug.org to contact a human being.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kwlug.org/pipermail/kwlug-disc_kwlug.org/attachments/20241231/b507e40f/attachment.htm>


More information about the kwlug-disc mailing list