Text Processingflags: gm
Markdown Heading
Matches markdown ATX-style headings (# through ######).
Try it in RegexProPattern
regexJavaScript
/^(#{1,6})\s+(.+)$/gmRaw 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
### SectionMatches
# Title## Subtitle### Section
Input
####### Not a headingNo match
—Common use cases
- Markdown parsers
- Table-of-contents generators
- Static site generators
Related concepts
Lazy vs. Greedy Quantifiers
ConceptGreedy quantifiers (*, +) consume as much as possible before backtracking. Lazy quantifiers (*?, +?) consume as little as possible.
Capturing Groups and Non-Capturing Groups
ConceptParentheses group tokens and capture the matched substring. (?:...) groups without capturing — use it when you want grouping for quantifiers or alternation but don't need the submatch.
How to Match Across Newlines in JavaScript
How-toThe dot doesn't match newlines by default. Use the s (dotall) flag, or build an explicit [\s\S] alternative for engines that predate s.