Page 1 of 1

Is it possible to use "fn.match" in ternary operators?

Posted: 18 Oct 2023, 16:17
by lemon389
Hello,

I would like to add a specific tag based on file title string or folder name string, but, avoiding it is duplicated.
In this case, sometimes the file has this tag, other times the folder has the tag or both might have the tag.

Groovy: Select all

{(fn.match(/Uncensored|Sin Censura|UNCEN/)) ? '[Uncensored]' : null} 
{(folder.name.match(/Uncensored|Sin Censura|UNCEN/)) ? '[Uncensored]' : null} 
I can gather this tag with above statements but, I would like to have something like this:

Groovy: Select all

{(fn.match(/Uncensored|Sin Censura|UNCEN/)) ? 
       '[Uncensored]' : 
       (folder.name.match(/Uncensored|Sin Censura|UNCEN/)) ? 
                    '[Uncensored]' : 
                     null
  '}
Problem:
The fn.match() and folder.name.match() never enter to the else statement of the ternary operator.

Question:
Is there another approach I can get this result?

Re: Is it possible to use "fn.match" in ternary operators?

Posted: 21 Oct 2023, 18:04
by rednoah
:idea: No, because match() never returns false and instead fails. See Learn how {expressions} work and useful Helper Functions for details.



:arrow: You can however use the regular Groovy find operator instead:

Format: Select all

{ fn =~ /Uncensored|Sin Censura|UNCEN/ ? '[Uncensored]' : null }



:arrow: In this specific case however, you'll probably want to just match something from the entire file path:

Format: Select all

{ f.path.match(/Uncensored|Sin Censura|UNCEN/); '[Uncensored]' }
or

Format: Select all

{ f =~ /Uncensored|Sin Censura|UNCEN/ ? '[Uncensored]' : null }

Re: Is it possible to use "fn.match" in ternary operators?

Posted: 23 Oct 2023, 00:22
by lemon389
Thanks for your support! I will try them!

Wish you a nice day!