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

Any questions? Need some help?
Post Reply
sselemit
Posts: 6
Joined: 28 Sep 2021, 09:55

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

Post 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,
User avatar
rednoah
The Source
Posts: 20273
Joined: 16 Nov 2011, 08:59

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

Post 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
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1199
Joined: 15 May 2014, 16:17

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

Post 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('.')}
User avatar
rednoah
The Source
Posts: 20273
Joined: 16 Nov 2011, 08:59

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

Post 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.
:idea: Please read the FAQ and How to Request Help.
sselemit
Posts: 6
Joined: 28 Sep 2021, 09:55

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

Post by sselemit »

Thank you for the help. My problem is solved now.
Post Reply