Page 1 of 1

[allOf] separators customization

Posted: 14 May 2020, 17:31
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

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

Posted: 14 May 2020, 20:01
by kim
the easy way:

Code: Select all

{(' ['+allOf{vs.match(/BluRay/)}{vf.match(/720p|1080p/)}.join('-')+']').replaceAll(/\[\]/)}

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

Posted: 14 May 2020, 22:21
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.

Re: [allOf] separators customization

Posted: 15 May 2020, 06:52
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('-', '[', ']')}

Re: [allOf] separators customization

Posted: 15 May 2020, 23:47
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

Re: [allOf] separators customization

Posted: 16 May 2020, 04:26
by rednoah
Yes, you may want to consider nesting allOf, or just calling multiple allOf in sequence and putting the separator in between yourself.