Firefox: Remark and RegEx Doesn't Work in executeScript_Sandbox

1.Below comments is not recognized in running, no matter // or /**/ , it will show " * [error] variable “I” is not defined"
2.Regex doesn’t work

var strCD = "AAA01";//${Arr[${i}][0]}.trim();
var CD_Tp = "Any";
if ( /^[A-Z]{3}$/.test(strCD) ){
  CD_Tp = "Internal Code";
} elseif ( /^[A-Z]{3}\d{2}$/.test(strCD) ){
  CD_Tp = "Internal Code";
} elseif ( /^[A-Z]{5}$/.test(strCD) ){
  CD_Tp = "UNLocode";
}

return CD_Tp;

version is 9.5.1

var strCD = "AAA01";
var CD_Tp = "Any";

if (/^[A-Z]{3}$/.test(strCD)) {
  CD_Tp = "Internal Code";
} else if (/^[A-Z]{3}\d{2}$/.test(strCD)) {
  CD_Tp = "Internal Code";
} else if (/^[A-Z]{5}$/.test(strCD)) {
  CD_Tp = "UNLocode";
}

return CD_Tp;

1 Like

Thank you for reminder for space between ‘else’ and ‘if’. But it shows "
*E501: [Firefox only] executeScript_Sandbox does not support regular expressions."

1 Like

It is working in Chrome

  {
      "Command": "executeScript_Sandbox",
      "Target": "var strCD = \"AAA01\";\n\n\nvar CD_Tp = \"Any\";\n\nif (/^[A-Z]{3}$/.test(strCD)) {\n  CD_Tp = \"Internal Code\";\n} else if (/^[A-Z]{3}\\d{2}$/.test(strCD)) {\n  CD_Tp = \"Internal Code\";\n} else if (/^[A-Z]{5}$/.test(strCD)) {\n  CD_Tp = \"UNLocode\";\n}\n\nreturn CD_Tp;\n",
      "Value": "aa",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${aa}",
      "Value": "",
      "Description": ""
    }
1 Like

You are both correct. Unfortunately executeScript_Sandbox can not process regular expressions in Firefox. Other than that, it works the same as in Chrome and Edge.

For technical reasons and workarounds please see this regular expressions post.