Text Processingflags: gm

Markdown Heading

Matches markdown ATX-style headings (# through ######).

Try it in RegexPro

Pattern

regexJavaScript
/^(#{1,6})\s+(.+)$/gm

Raw source: ^(#{1,6})\s+(.+)$

How it works

`^(#{1,6})` captures 1–6 hash characters at line start. `\s+` requires whitespace. `(.+)$` captures the heading text to end of line.

Examples

Input

# Title ## Subtitle ### Section

Matches

  • # Title
  • ## Subtitle
  • ### Section

Input

####### Not a heading

No match

Common use cases

  • Markdown parsers
  • Table-of-contents generators
  • Static site generators

Related concepts