{"record":{"id":"4cac54e6a32ca028","repo":"meteor/meteor","slug":"only-the-i-m-and-g-regexp-options-are-supported","errorCode":null,"errorMessage":"Only the i, m, and g regexp options are supported","messagePattern":"Only the i, m, and g regexp options are supported","errorType":"exception","errorClass":"MiniMongoQueryError","httpStatus":null,"severity":"error","filePath":"packages/minimongo/common.js","lineNumber":185,"sourceCode":"      };\n    },\n  },\n  $regex: {\n    compileElementSelector(operand, valueSelector) {\n      if (!(typeof operand === 'string' || operand instanceof RegExp)) {\n        throw new MiniMongoQueryError('$regex has to be a string or RegExp');\n      }\n\n      let regexp;\n      if (valueSelector.$options !== undefined) {\n        // Options passed in $options (even the empty string) always overrides\n        // options in the RegExp object itself.\n\n        // Be clear that we only support the JS-supported options, not extended\n        // ones (eg, Mongo supports x and s). Ideally we would implement x and s\n        // by transforming the regexp, but not today...\n        if (/[^gim]/.test(valueSelector.$options)) {\n          throw new MiniMongoQueryError('Only the i, m, and g regexp options are supported');\n        }\n\n        const source = operand instanceof RegExp ? operand.source : operand;\n        regexp = new RegExp(source, valueSelector.$options);\n      } else if (operand instanceof RegExp) {\n        regexp = operand;\n      } else {\n        regexp = new RegExp(operand);\n      }\n\n      return regexpElementMatcher(regexp);\n    },\n  },\n  $elemMatch: {\n    dontExpandLeafArrays: true,\n    compileElementSelector(operand, valueSelector, matcher) {\n      if (!LocalCollection._isPlainObject(operand)) {\n        throw new MiniMongoQueryError('$elemMatch need an object');","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/meteor/meteor/blob/5076d2f818d3cac01d0cf8312fa5b2332076a4fb/packages/minimongo/common.js#L167-L203","documentation":"Thrown by the $regex operator when the accompanying $options string contains any character other than i, m, or g. minimongo only supports the JavaScript RegExp flags; MongoDB-specific flags like x (extended) and s (dotAll) are not implemented and are explicitly rejected.","triggerScenarios":"Using {field: {$regex: 'a.b', $options: 'is'}} or {field: {$regex: 'a.b', $options: 'x'}} in a minimongo query. The check /[^gim]/.test(valueSelector.$options) catches any unsupported flag.","commonSituations":"Copying a query from MongoDB shell that uses x or s flags; combining flags and including an unsupported one; passing options as a multi-char string with a typo.","solutions":["Use only i, m, and/or g: {field: {$regex: 'a.b', $options: 'im'}}.","Drop the unsupported flag, or pre-process the regex to simulate x (strip whitespace/comments) or s (transform . ) client-side.","If you need dotAll, rewrite the pattern to use [\\s\\S] instead of relying on the s flag."],"exampleFix":"// before\ncollection.find({ body: { $regex: 'a.b', $options: 'is' } });\n// after\ncollection.find({ body: { $regex: 'a[\\s\\S]b', $options: 'i' } });","handlingStrategy":"validation","validationCode":"function regexWithOptions(pattern, options) {\n  if (options && /[^gim]/.test(options)) {\n    throw new Error('Only i, m, g flags are supported by minimongo');\n  }\n  return { $regex: pattern, $options: options || '' };\n}","typeGuard":"function areValidRegexFlags(flags) {\n  return typeof flags === 'string' && /^[gim]*$/.test(flags);\n}","tryCatchPattern":null,"preventionTips":["Restrict $options to i, m, and g.","Rewrite patterns needing s flag to use [\\\\s\\\\S].","Strip x-flag and pre-remove whitespace/comments manually if needed."],"tags":["minimongo","query","operator","regex","options","validation"],"backgroundTag":null,"analyzedSha":"5076d2f818d3cac01d0cf8312fa5b2332076a4fb","analyzedAt":"2026-08-13T03:27:40.142Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}