ginjaninja 537 Posted December 31, 2022 Share Posted December 31, 2022 https://regex101.com/r/kDRIuA/1 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 More sharing options...
Cheesegeezer 3087 Posted December 31, 2022 Share Posted December 31, 2022 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 More sharing options...
ginjaninja 537 Posted December 31, 2022 Author Share Posted December 31, 2022 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 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 More sharing options...
ginjaninja 537 Posted December 31, 2022 Author Share Posted December 31, 2022 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 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 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now