badges/shields · error · InvalidParameter
Invalid re2 regex: ${error.message}
Error message
Invalid re2 regex: ${error.message} What it means
Thrown by the dynamic-regex service when new RE2(search, flags) raises a SyntaxError, i.e. the supplied search pattern is not a syntactically valid RE2 regular expression. RE2 is stricter than PCRE in places, so patterns valid in other engines can fail here. SyntaxErrors are converted into a 404-style InvalidParameter badge; other errors are rethrown.
Source
Thrown at services/dynamic/dynamic-regex.service.js:86
}
static defaultBadgeData = { label: 'match' }
static validate(flags) {
if (flags?.split('')?.some(c => VALID_FLAGS.indexOf(c) === -1)) {
throw new InvalidParameter({
prettyMessage: `Invalid flags, must be one of: ${VALID_FLAGS}`,
})
}
}
static transform(buffer, search, replace, flags) {
// build re2 regex
let re2
try {
re2 = new RE2(search, flags)
} catch (error) {
if (error instanceof SyntaxError) {
throw new InvalidParameter({
prettyMessage: `Invalid re2 regex: ${error.message}`,
})
}
throw error
}
// extract value
const found = re2.exec(buffer)
if (found == null) {
throw new InvalidResponse({
prettyMessage: 'no result',
})
}
// replace if needed
return replace !== undefined ? found[0].replace(re2, replace) : found[0]
}
View on GitHub (pinned to 766fd8bc89)
Solutions
- Test the pattern in an RE2-compatible tester before embedding it in the badge URL.
- Rewrite lookarounds and backreferences using RE2-supported constructs (non-capturing groups, explicit alternation).
- URL-encode the search parameter so regex metacharacters survive query parsing.
- Simplify or reduce the regex to the minimal expression needed to match the value.
Example fix
// before search="version":\s*"(\d+\.\d+)"(?=,) // after (RE2: drop lookahead) search="version":\s*"(\d+\.\d+)"
Defensive patterns
Strategy: validation
Validate before calling
const RE2 = require('re2');
function validateRegex(pattern, flags = '') {
try {
new RE2(pattern, flags); // throws SyntaxError if invalid
return true;
} catch (e) {
if (e instanceof SyntaxError) throw new Error(`Invalid re2 regex: ${e.message}`);
throw e;
}
} Type guard
function isValidRe2(pattern, flags = '') {
try { new (require('re2'))(pattern, flags); return true; } catch { return false; }
} Try / catch
try {
const badge = await dynamicRegex({ url, search, replace, flags });
} catch (err) {
if (String(err.message).startsWith('Invalid re2 regex:')) {
// fix the pattern: remove lookarounds/backreferences, check escaping
} else {
throw err;
}
} Prevention
- Test patterns in an RE2-compatible tester before embedding in a badge URL.
- Avoid RE2-unsupported constructs: lookarounds, backreferences, atomic groups.
- URL-encode the search parameter so regex metacharacters survive query parsing.
When it happens
Trigger: Any badge request whose search parameter fails to compile under RE2 — unbalanced parentheses/brackets, dangling quantifier, unsupported constructs like lookbehind/lookahead ((?=...), (?<=...)), backreferences (\1), or invalid escape sequences.
Common situations: Using PCRE-only features (lookarounds, backreferences) that RE2 does not support; escaping mistakes in URL query strings; hand-edited regex with a missing bracket; switching from a JS regex engine to RE2 without adjusting the pattern.
Related errors
- Invalid flags, must be one of: ${VALID_FLAGS}
- Field `idSuffix` must contain only numbers, letters, -, and
- invalid api key
- monitor API key is unvalid
- must use a monitor-specific api key
AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30).
Data as JSON: /api/errors/6ae06a2f1aa7e599.
Report an issue: GitHub.