Page 1 of 1

I'm having issues with Matching 2 groups of words

Posted: 24 Jun 2019, 00:01
by DevXen
So This used to work. i'm not sure when it stopped working as I've been pretty busy working. and dealing with my broken elbow. I'm not sure if it was changed in an update, or what. but it apparently hasn't been working in awhile.

The idea is to match a single word from group one. and add that to the file name. and if there is a second word matched from group two add that along with the word from group one. I.E.:

Code: Select all

(Unrated|Extended)+(Version|Edit|cut)

this is the code i've been working with. I was pretty sure, I read this was possible with the + at the end of the first froup and ?: at the start of the second. meaning it'll match the first group. and check for the second but not fail the first group if a match to the second isn't found. but if it is found add it to the returned result.

Code: Select all

{" ["+file.path.lower().matchAll(/(uncensored|uncut|unrated|remastered|ultimate|extended|director?s|theatrical|ultimate|final|bootleg|special|fan?edit?|limited|rifftrax|monstervision|youtube|hulu|netflix|vimeo|edited|edit|censored+)(?:.edition|.cut|.version|.edit|.release|.extended|.rip)?/)*.upperInitial()*.lowerTrail().sort().join('] [')+']'}

-DevXen

Re: I'm having issues with Matching 2 groups of words

Posted: 24 Jun 2019, 02:49
by rednoah
Note that String.match(...) and String.matchAll(...) automatically give you Capturing Group 1, if there are capturing groups. Maybe this feature just didn't work for String.matchAll(...) until some rewrite? Not sure.


e.g.

Code: Select all

"Part 1".match(/Part (\d)/) // return "1" (as opposed to Part 1)
"Part 1".match(/Part \d/) // return "Part 1"

e.g. adding a (...) around your regex will ensure that Group 1 is the entire match:

Code: Select all

{"Unrated Cut".matchAll(/((Unrated.|Extended.)(Version|Edit|Cut))/)}

Code: Select all

[Unrated Cut]

Re: I'm having issues with Matching 2 groups of words

Posted: 24 Jun 2019, 02:55
by DevXen
I was actually reading that. But the problem I had is I need it to return just the result from group one. If it matches with no result from group 2 as well.

Also I did use an online regex checker and it returned the matches as I expected. So it was strange. Haha

Re: I'm having issues with Matching 2 groups of words

Posted: 24 Jun 2019, 03:07
by rednoah
Ah. Well, right now it'll give you the entire match if you're not using (...) groups, or Group 1, which means Group 2..N are not part of the return value.

:idea: Not sure if behaviour makes sense if 2 or more groups are being used. Maybe there's a case to be made to just concat all the Group 1..N values. Though it would break backwards compatibility a little, if people are relying on the somewhat vaguely defined current behaviour.

Re: I'm having issues with Matching 2 groups of words

Posted: 24 Jun 2019, 03:14
by DevXen
its to add extra info to the file. stuff like Lifetime, Rifftrax, as well as stuff like director's cut. and widescreen, and the examples above like Unrated Cut|Edition|Edit| I actually have a lot I've added to both groups over the last couple years.
Though I suppose I could just make 2 different matches. one for absolute matches. and one that has the possibility of the second word.

But then again. some of those Uncut/Unrated/ don't have an edition or cut, or edit, etc. so those are just kinda based on the specific movie
Hmm.


Ooo Though I could put both of them in am $any{} check I suppose. check for 2 words. if none then check for the single word. though that will make my script much larger. that might actually be a doable solution.

Re: I'm having issues with Matching 2 groups of words

Posted: 24 Jun 2019, 04:27
by DevXen
So.. it appears I did it. Wahoo!

Code: Select all

.matchAll(/((unrated|extended)+(.version|.edition|.edit|.cut)?)/)
]

Though. if the file has a period in it between the two names. the only way I could find to remove it. was to do a replace before the regex.

My actual testing code:

Code: Select all

{"["+"unrated.extended.edition".replace(/./,' ').matchAll(/((imax|unrated|extended)+(version|.edition|.edit|.cut)?)/)*.upperInitial()*.lowerTrail().sort().join('] [')+']'}

Re: I'm having issues with Matching 2 groups of words

Posted: 24 Jun 2019, 04:56
by kim
like so ?

Code: Select all

{"["+"unrated.extended.edition".matchAll(/((?:imax|unrated|extended)(?:.(?:version|edition|edit|cut))?)/)*.upperInitial()*.lowerTrail().sort().join('] [').space(' ')+']'}

Re: I'm having issues with Matching 2 groups of words

Posted: 27 Jun 2019, 03:27
by rednoah
(?:ABZ) makes it a non-capturing group, which is an alternative approach you can use to ensure Capturing Group 1 is what you want it to be, or doesn't exist so FileBot defaults to Capturing Group 0 (i.e. the entire match).