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

Any questions? Need some help?
Post Reply
lemon389
Posts: 15
Joined: 24 Sep 2023, 22:25

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

Post 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?
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

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

Post 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 }
:idea: Please read the FAQ and How to Request Help.
lemon389
Posts: 15
Joined: 24 Sep 2023, 22:25

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

Post by lemon389 »

Thanks for your support! I will try them!

Wish you a nice day!
Post Reply