Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
Python

r"
^[\{\(\[]?(?P<studio>.+?)[\}\)\]]?([\-\ ]{2,3}|\]\s)(?P<clip_name>.+)
"
gm

Description

Separate Studio/Movie Title Info From Filename for Plex

This regex is ultimately used by a Plex Media Server Agent to parse various information from a filename when Plex is scanning a media directory.

The regex uses named groups studio and clip_name to store the information that is parses so that it can be easily referred to pragmatically by Plex.

Examples

The following examples show how the regex parses the filename passed to it by Plex. Note that Plex passed the filename only and removes the file extension and directory.

Filename; [Studio Name] - Movie Title parses into: studio: Studio Name clip_name: Movie Title

The regex accommodates for several variations in the filename:

Filename: [Studio Name] Movie Title
Filename: (Studio Name) - Movie Title
Filename: (Studio Name) Movie Title Filename: Studio Name - Movie Title Filename: {Studio Name} - Movie Title Filename: {Studio Name} Movie Title

will all parse the same and have the same result as the first example.

Submitted by anonymous - 6 years ago