Page 1 of 1

How to make String.match(regex) case sensitive?

Posted: 29 Sep 2021, 07:53
by sselemit
My problem is that I'm trying to preserve the "NF" tag from filename but the match function is case insensitive by default so it matches "nf" in the name of the show, which I don't want. All other names that have "nf" in them also got matched. Same thing applies to other tags such as "CC, CR, CW, iP". NF is a tag for Netflix

Example:
"Confession" TV show got matched but does not come from Netflix


My code:

Code: Select all

{fn.match(/ABC|ATVP|AMZN|BBC|CBS|CC|CR|CW|DCU|DSNP|DSNY|Disney[+]|DisneyPlus|FBWatch|FREE|FOX|HBO|HMAX|HULU|iP|LIFE|MTV|NBC|NICK|NF|RED|TF1|STZ/)} 
Thank you,

Re: How to make String.match(regex) case sensitive?

Posted: 29 Sep 2021, 12:10
by rednoah
You can use the -i modifier to force a case-sensitive pattern:

Code: Select all

{ fn.match(/(?-i:test)/) }

Code: Select all

{ fn.match(/(?-i:ABC|ATVP|AMZN|BBC|CBS|CC|CR|CW|DCU|DSNP|DSNY|Disney[+]|DisneyPlus|FBWatch|FREE|FOX|HBO|HMAX|HULU|iP|LIFE|MTV|NBC|NICK|NF|RED|TF1|STZ)/) } 
:idea: https://www.regular-expressions.info/refmodifiers.html

Re: How to make String.match(regex) case sensitive?

Posted: 29 Sep 2021, 23:49
by kim
what about Word Boundaries ?
https://www.regular-expressions.info/wo ... aries.html

can it match more then one, no... if needed then use matchAll

Code: Select all

{ fn.matchAll(/\b(?-i:ABC|ATVP|AMZN|BBC|CBS|CC|CR|CW|DCU|DSNP|DSNY|Disney[+]|DisneyPlus|FBWatch|FREE|FOX|HBO|HMAX|HULU|iP|LIFE|MTV|NBC|NICK|NF|RED|TF1|STZ)\b/).join('.')}

Re: How to make String.match(regex) case sensitive?

Posted: 30 Sep 2021, 02:51
by rednoah
Using the word boundary matcher \b is a good idea. But keep in mind that \b does not see _ as a word boundary, which can be unintuitive since _ is often used as a space replacement, so it might work well for some file names, but less well for others.

Re: How to make String.match(regex) case sensitive?

Posted: 30 Sep 2021, 13:38
by sselemit
Thank you for the help. My problem is solved now.