cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar
nikles
Level VI

How to make Regex case insensitive

Hi.  Does anyone know the best way to make a regex search case insensitive in JSL?  For example, I wish to extract the file extension from a path name, and I don't want it to matter if the extension is ".csv" or ".CSV" or ".cSv".  If I try the following, it will only work on filenames whose extensions are lowercase:

 

filename = Regex(path, "(.+\/)*([^\/]+)\.(csv|xlsx)$", "\2")

 

One method is to just convert the entire path to lowercase before doing regex on it, but for various reasons I don't want to do that.  

 

filename = Regex(LowerCase(path), "(.+\/)*([^\/]+)\.(csv|xlsx)$", "\2")

 

The other method I tried is to use the "(?i)" modifier in the match string, but I get an error:

filename = Regex(path, "(?i)(.+\/)*([^\/]+)\.(csv|xlsx)$", "\2")

"regex found a quantifier *, +, ?, or {  in an invalid position, the result is undefined in access or evaluation of 'Regex'".  I'm guessing that modifier is not supported in JSL.  Any ideas?

1 REPLY 1
jthi
Super User

Re: How to make Regex case insensitive

If you wish to extract file extension I would suggest checking out Word(), Words(), Item() and Items() functions instead of using Regex.

-Jarmo