[allOf] separators customization

All about user-defined episode / movie format expressions
Post Reply
AbedlaPaille
Posts: 97
Joined: 12 Apr 2020, 04:02

[allOf] separators customization

Post by AbedlaPaille »

Struggling with an aspect of allOf, separators customization. By default it limits with brackets and puts a comma and a space in between.
.join() custom function acts on comma+space but loses the brackets on both ends.

How to keep the brackets with a custom .join() ? The way to combine variables and separators from the real world examples above doesn't work like usual it seems.

e.g. I'm trying to retain video source if BluRay, video format if 1080p or 720p, have brackets on both ends and separate with dash

Code: Select all

{' ['+allOf{vs.match(/BluRay/)}{vf.match(/720[pP]|1080[pP]/)}.join('-')+']'}
As long as at least one variable returns it works, but it'll keep the brackets if none return. Might as well put the brackets outside the expression because it's failing completely what i'm trying to do :D
kim
Power User
Posts: 1027
Joined: 15 May 2014, 16:17

Re: Learn how {expressions} work and useful Helper Functions

Post by kim »

the easy way:

Code: Select all

{(' ['+allOf{vs.match(/BluRay/)}{vf.match(/720p|1080p/)}.join('-')+']').replaceAll(/\[\]/)}
AbedlaPaille
Posts: 97
Joined: 12 Apr 2020, 04:02

Re: Learn how {expressions} work and useful Helper Functions

Post by AbedlaPaille »

Thanks works perfectly! Can you explain why the .replaceAll becomes needed and/or what the symbols inside mean and do? Or a relevant link for that kind of syntax. Anyway thanks a lot.
User avatar
rednoah
The Source
Posts: 19015
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [allOf] separators customization

Post by rednoah »

That part just replaces [] with nothing:

Code: Select all

{"[][1][2]".replaceAll(/\[\]/)}
Though there is an alternative that will take care of empty lists implicitely:

Code: Select all

{allOf{1}{2}{3}.joining('-', '[', ']')}
:idea: Please read the FAQ and How to Request Help.
AbedlaPaille
Posts: 97
Joined: 12 Apr 2020, 04:02

Re: [allOf] separators customization

Post by AbedlaPaille »

Code: Select all

{allOf{1}{2}{3}.joining('-', '[', ']')}
Even cleaner, perfect! I was writing just that in my tests before posting but i was using .join instead of .joining .. grumbles

[edit] Feel terrible because i realise you had already showed me the way in a previous thread.. :? [/edit]

Can it delve further inside separator customization that cleanly? eg first separator '-', second ' ', third '--' etc ?

Think i've seen people use a allOf within another allOf to achieve that
User avatar
rednoah
The Source
Posts: 19015
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [allOf] separators customization

Post by rednoah »

Yes, you may want to consider nesting allOf, or just calling multiple allOf in sequence and putting the separator in between yourself.
:idea: Please read the FAQ and How to Request Help.
Post Reply