code: function toRegExp(val, def) {
      var exp = /^\/.+\/(g|i|m)?([m,i,u,y]{1,4})?/;
      var optsExp = /(g|i|m)?([m,i,u,y]{1,4})?$/;
      if (is_1.isRegExp(val))
          return val;
      if (!is_1.isValue(val) || !is_1.isString(val))
          return toDefault(null, def);
      function regExpFromStr() {
          var opts;
          if (exp.test(val)) {
              opts = optsExp.exec(val)[0];
              val = val.replace(/^\//, '').replace(optsExp, '').replace(/\/$/, '');
          }
          return new RegExp(val, opts);
      }
      return function_1.tryWrap(regExpFromStr)(def);
  }
docs: To Regular Expression
  Attempts to convert to a regular expression
  from a string.
  
  @param val the value to convert to RegExp.
  @param def optional express as default on null.