diff --git a/tools/doc/allhtml.mjs b/tools/doc/allhtml.mjs
index 54a51dd6316010..905ea5d3dd6c6f 100644
--- a/tools/doc/allhtml.mjs
+++ b/tools/doc/allhtml.mjs
@@ -76,13 +76,13 @@ fs.writeFileSync(new URL('./all.html', source), all, 'utf8');
// Validate all hrefs have a target.
const ids = new Set();
-const idRe = / id="(\w+)"/g;
+const idRe = / id="([^"]+)"/g;
let match;
while (match = idRe.exec(all)) {
ids.add(match[1]);
}
-const hrefRe = / href="#(\w+)"/g;
+const hrefRe = / href="#([^"]+)"/g;
while (match = hrefRe.exec(all)) {
if (!ids.has(match[1])) throw new Error(`link not found: ${match[1]}`);
}