function checkRegex(
			nodeToReport,
			pattern,
			rawPattern,
			rawPatternStartRange,
			flags,
		) {
			// Skip if there are no consecutive spaces in the source code, to avoid reporting e.g., RegExp(' \ ').
			if (!DOUBLE_SPACE.test(rawPattern)) {
				return;
			}

			const characterClassNodes = [];
			let regExpAST;

			try {
				regExpAST = regExpParser.parsePattern(
					pattern,
					0,
					pattern.length,
					{
						unicode: flags.includes("u"),
						unicodeSets: flags.includes("v"),
					},
				);
			} catch {
				// Ignore regular expressions with syntax errors
				return;
			}

			regexpp.visitRegExpAST(regExpAST, {
				onCharacterClassEnter(ccNode) {
					characterClassNodes.push(ccNode);
				},
			});

			const spacesPattern = /( {2,})(?: [+*{?]|[^+*{?]|$)/gu;
			let match;

			while ((match = spacesPattern.exec(pattern))) {
				const {
					1: { length },
					index,
				} = match;

				// Report only consecutive spaces that are not in character classes.
				if (
					characterClassNodes.every(
						({ start, end }) => index < start || end <= index,
					)
				) {
					context.report({
						node: nodeToReport,
						messageId: "multipleSpaces",
						data: { length },
						fix(fixer) {
							if (pattern !== rawPattern) {
								return null;
							}
							return fixer.replaceTextRange(
								[
									rawPatternStartRange + index,
									rawPatternStartRange + index + length,
								],
								` {${length}}`,
							);
						},
					});

					// Report only the first occurrence of consecutive spaces
					return;
				}
			}
		}
Validate regular expression
@param {ASTNode} nodeToReport Node to report.
@param {string} pattern Regular expression pattern to validate.
@param {string} rawPattern Raw representation of the pattern in the source code.
@param {number} rawPatternStartRange Start range of the pattern in the source code.
@param {string} flags Regular expression flags.
@returns {void}
@private