Jump to content

Regex Help with Movie Naming Scheme


ginjaninja

Recommended Posts

ginjaninja

https://regex101.com/r/kDRIuA/1

image.png.d5f12f31479bfdc2b2f87814560d09d8.png

Could any one explain how to make the year capturing group take precedence over the version capturing group...if the year capturing group exists it must be captured. the version capturing group cant take precedence over the year.

i think i need to make the title lazy so the year is captured if it exists..but equally the year sometimes doesnt exist so has to set to 0 or 1...but then the version has the ability to sneak in and take precedence over the year.

treat me like a regex noob, solution would be great, explanation would be even better.

Link to comment
Share on other sites

Cheesegeezer

I would capture the version in your case, stick it in a variable and then remove the variable from the filename and do what you need and then put it back if required 

Link to comment
Share on other sites

ginjaninja
1 hour ago, Cheesegeezer said:

I would capture the version in your case, stick it in a variable and then remove the variable from the filename and do what you need and then put it back if required 

thanks, it might come to that but wouldnt i  still need to ensure the version capture group doesnt contain patterns which match years or parts?

i think i am getting closer using look arounds to ensure one capture group doesnt end like another (at least that what i think its doing)

https://regex101.com/r/JZUVzt/2

image.png.62c43d33835dd38053a40fb5d09a9e8a.png

would love to know if there is a syntax that says this pattern can not appear anywhere in this capture group.

Link to comment
Share on other sites

ginjaninja

matching righttoleft seems to offer something... the title is not so bound but the version, part, provider id and year have a very specific structure which seem to be more easily compartmentalised righttoleft

https://regex101.com/r/JZUVzt/3

image.png.b4914759a11992a7365775f3f2803ecb.png

in powershell

$string = $filename
$pattern = '^(?<Title>.*?)( \((?<Year>\d\d\d\d)\))?( (?<Providerid>\[tmdb=\d*\]))?(?<part>-part\d)?( - (?<Version>.*?(?<! \(\d\d\d\d\))(?<!-part\d)(?<!\d\d\d\])))?$'
$options = [System.Text.RegularExpressions.RegexOptions]'RightToLeft,IgnoreCase'
$matches = [regex]::Matches($string, $pattern, $options)

$title = ($matches.groups | Where-Object { $_.name -eq 'title' }).captures.value

 

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...