Zero-dependency, TypeScript-typed RegExp patterns for extracting headers, links, images, lists and code from Markdown.
v2.1.0 is tagged and released on GitHub. The npm
latesttag is still 1.2.0. Treat v2 as a preview until an npm 2.x publish lands.
Requires Node.js 20+. CI builds on Node 20, 22, and 24.
- Agent guide: https://github.com/LLazyEmail/markdown-regex/blob/main/AGENTS.md
- Full API: https://github.com/LLazyEmail/markdown-regex/blob/main/llms-full.txt
- Source index: https://github.com/LLazyEmail/markdown-regex/blob/main/src/index.ts
Use markdown-regex for quick extraction, linting, or lightweight transforms.
Do not use it when you need an AST or CommonMark compliance. Use remark, micromark, or markdown-it.
| Channel | Version | Notes |
|---|---|---|
GitHub main / Release 2.1.0 |
2.1.0 | TypeScript rewrite |
npm latest |
1.2.0 | Legacy JavaScript API |
| Package name | markdown-regex |
Same name on GitHub and npm |
npm install github:LLazyEmail/markdown-regex#mainimport { extractLinks, extractHeaders, REGEXP_LINK } from 'markdown-regex';
extractLinks('[a](b)');
// [{ text: 'a', url: 'b' }]
extractHeaders('# Title');
// [{ level: 1, text: 'Title' }]
'[a](b)'.match(REGEXP_LINK);
// ['[a](b)', 'a', 'b']Every regex is global (g). Reset .lastIndex between .test() calls, or use matchAll.
See the tables in this README and llms-full.txt. HTML cleanup lives on markdown-regex/cleanup.
import { REGEXP_EMPTY_UL } from 'markdown-regex/cleanup';
import { extractLinks } from 'markdown-regex';- Nested emphasis is not fully handled.
REGEXP_LINKon raw Markdown matches inside code. UseextractLinks().- Reference links and setext headers are not matched.
- See SECURITY.md for ReDoS. CI runs
tests/redos.test.tson every exported pattern.
npm install
npm run build
npm run typecheck
npm test
npm run test:coverageTests are Vitest (tests/**/*.test.ts). Jest is not used.
CI builds on Node 20, 22, and 24.
- NPM: https://www.npmjs.com/package/markdown-regex
- Used by: https://github.com/LLazyEmail/markdown-to-email
- Article: https://hackernoon.com/open-sourcing-regular-expressions-for-markdown-syntax-module
- Agent guide: https://github.com/LLazyEmail/markdown-regex/blob/main/AGENTS.md
- Full API: https://github.com/LLazyEmail/markdown-regex/blob/main/llms-full.txt
- Source index: https://github.com/LLazyEmail/markdown-regex/blob/main/src/index.ts
MIT