Hi, all... I am validating user supplied input. The first step is working fine. Their supplied value, dropped toLowerCase(), has to be in the array of: const valLoc = [ "head", "hand", "arm", "shoulder", "chest", "stomach", "vitals", "thigh", "leg", "foot", "headshot", "highshot", "bodyshot", "lowshot", "legshot", "random", "none", "hands", "arms", "shoulders", "thighs", "legs","feet", ]; If they supply something else, my variable gets defaulted to "random." If they supply one of the plural versions, however (hands, feet, arms, etc.), I want to return the singular version. The following version of doing that works (assume input is what the user supplied, and valInput is what I want to return): toSingular = { "hands": "hand", "arms": "arm", "shoulders": "shoulder", "thighs": "thigh", "legs": "leg", "feet": "foot", }; valInput = input.replace(/hands|arms|shoulders|thighs|legs|feet/gi, function (matched) { return toSingular[matched]; }); But, it's cumbersome and error-prone to have to type up the keys again. (Besides, I'd like to do this in another replace operation that has about 50 such keys.) The good news seemed to be that by using Object.keys(...) I could get the keys of that list, join them with a pipe character, and construct a new RegExp out of them. Or, I should be able to: toSingular = {
"hands": "hand",
"arms": "arm",
"shoulders": "shoulder",
"thighs": "thigh",
"legs": "leg",
"feet": "foot", }; valInput = input.replace(new RegExp(Object.keys(toSingular).join("|"),'gi'), function (matched) { return toSingular[matched]; }); I can do this in this fiddle , however, when I try to do it in my roll20 script, my sandbox breaks with a "RegExp is not a constructor" error. I am not super fluent with javascript, so if it matters, the line above is positioned in the script like so: var scriptName = scriptName || (function () { 'use strict, foo = function () {...}, bar = function () {...}, ... qux = function (input) { // code would be here return valInput; }, ... }()); I mention that because outside one of these inner functions, the RegExp constructor seems to work fine. What am I missing?