A set of ready-to-use RegExp constants for parsing and extracting elements from Markdown content.
- 17 regex patterns covering all common Markdown elements
- Cross-platform support (Windows
\r\nand Unix\nline endings) - Zero runtime dependencies
- TypeScript definitions included
- Lightweight (~2 KB)
npm install markdown-regexyarn add markdown-regexconst { REGEXP_HEADER, REGEXP_LINK } = require('markdown-regex');import { REGEXP_HEADER, REGEXP_LINK } from 'markdown-regex';| Export | Description | Matches |
|---|---|---|
REGEXP_HEADER |
Markdown headers | # H1, ## H2, ### H3 |
REGEXP_IMAGE |
Image syntax |  |
REGEXP_LINK |
Link syntax | [text](url) |
REGEXP_STRONG |
Bold text | **bold**, __bold__ |
REGEXP_EM |
Italic/emphasis | *italic*, _italic_ |
REGEXP_DEL |
Strikethrough | ~~deleted~~ |
REGEXP_CODE |
Inline code | `code` |
REGEXP_Q |
Quoted text | :"quoted": |
REGEXP_BLOCKQUOTE |
Blockquotes | > quote |
REGEXP_HR |
Horizontal rules | ----- (5+ dashes) |
REGEXP_PARAGRAPH |
Paragraphs | Block of text between newlines |
REGEXP_BR |
Line breaks | Two or more consecutive newlines |
REGEXP_EMPTY_BLOCKQUOTE |
Consecutive blockquote HTML tags | </blockquote><blockquote> |
REGEXP_UL_LIST |
Unordered list items | * item |
REGEXP_OL_LIST |
Ordered list items | 1. item |
REGEXP_EMPTY_UL |
Consecutive unordered list HTML tags | </ul><ul> |
REGEXP_EMPTY_OL |
Consecutive ordered list HTML tags | </ol><ol> |
import { REGEXP_LINK } from 'markdown-regex';
const markdown = 'Visit [GitHub](https://github.com) and [npm](https://npmjs.com).';
const matches = markdown.match(REGEXP_LINK);
console.log(matches);
// [ '[GitHub](https://github.com)', '[npm](https://npmjs.com)' ]import { REGEXP_HEADER } from 'markdown-regex';
const markdown = '\n# Title\n## Subtitle\n### Section';
const matches = markdown.match(REGEXP_HEADER);
console.log(matches);
// [ '\n# Title', '\n## Subtitle', '\n### Section' ]import { REGEXP_IMAGE } from 'markdown-regex';
const markdown = 'Here is an .';
const matches = markdown.match(REGEXP_IMAGE);
console.log(matches);
// [ '' ]See examples/basic-usage.js for a more comprehensive demonstration.
TypeScript definitions are included. No @types/ package is needed:
import { REGEXP_LINK, REGEXP_HEADER } from 'markdown-regex';
const links: RegExpMatchArray | null = text.match(REGEXP_LINK);Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
See CHANGELOG.md for release history.
