matchValidator = function(v) {
    if (!regExp) {
      return false;
    }

    // In case RegExp happens to have `/g` flag set, we need to reset the
    // `lastIndex`, otherwise `match` will intermittently fail.
    regExp.lastIndex = 0;

    const ret = ((v != null && v !== '')
      ? regExp.test(v)
      : true);
    return ret;
  }
Sets a regexp validator.

Any value that does not pass `regExp`.test(val) will fail validation.

#### Example:

    const s = new Schema({ name: { type: String, match: /^a/ }})
    const M = db.model('M', s)
    const m = new M({ name: 'I am invalid' })
    m.validate(function (err) {
      console.error(String(err)) // "ValidationError: Path `name` is invalid (I am invalid)."
      m.name = 'apples'
      m.validate(function (err) {
        assert.ok(err) // success
      })
    })

    // using a custom error message
    const match = [ /\.html$/, "That file doesn't end in .html ({VALUE})" ];
    const s = new Schema({ file: { type: String, match: match }})
    const M = db.model('M', s);
    const m = new M({ file: 'invalid' });
    m.validate(function (err) {
      console.log(String(err)) // "ValidationError: That file doesn't end in .html (invalid)"
    })

Empty strings, `undefined`, and `null` values always pass the match validator. If you require these values, enable the `required` validator also.

    const s = new Schema({ name: { type: String, match: /^a/, required: true }})

@param {RegExp} regExp regular expression to test against
@param {String} [message] optional custom error message
@return {SchemaType} this
@see Customized Error Messages https://mongoosejs.com/docs/api/error.html#Error.messages
@api public