How to make Regex case insensitiveHi. 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?
Automation and ScriptingRe: How to make Regex case insensitiveIf you wish to extract file extension I would suggest checking out Word(), Words(), Item() and Items() functions instead of using Regex.
Re: How to make Regex case insensitiveThere is also IGNORECASE flag in Regex in JMP, but still I would suggest using other methods than regex if you just want the filename (or extension or both)
Names Default To Here(1);
path = Convert File Path("$SAMPLE_DATA/Big Class.jmp");
filename1 = Regex(path, "(.+\/)*([^\/]+)\.(JMP)$", "\2", IGNORECASE);
filename2 = Word(-2, path, "\/.");
filename3 = Word(-1, path, "\/");
Show(filename1, filename2, filename3);

Regex(source, pattern, (, >)
Scripting Guide > Types of Data > Regular Expressions > Regex Function
Re: How to make Regex case insensitiveThis hybrid code works
Names Default To Here( 1 );
path = "C:\users\big.cSv";
filename = "";
ext = Word( -1, path, "." );
If( Uppercase( ext ) == "CSV" | Uppercase( ext ) == "XLSX",
filename = Eval(
Parse(
"Regex(path, \!"(.+\/)*([^\/]+)\." || ext || "$\!", \!"\2\!")"
)
)
);
Show( filename );
My preferred JSL is
Names Default To Here( 1 );
path = "C:\users\big.cSv";
filename = "";
ext = Word( -1, path, "." );
If( Uppercase( ext ) == "CSV" | Uppercase( ext ) == "XLSX",
filename = Word( -2, path, ".\/" )
);
Show( filename );
Re: How to make Regex case insensitiveThanks @jthi . I knew I'd seen this somewhere. Of course it was in the scripting guide. Ha.