code: function asRegExp(pattern) {
    // if regex then return it
    if (isRegExp(pattern)) {
      return pattern;
    }
  
    // if string then test for valid regex then convert to regex and return
    const match = pattern.match(REGEX);
    if (match) {
      return new RegExp(match[1], match[2]);
    }
  
    return new RegExp(pattern);
  }
docs: regular expression to test a regular expression