Markdown is line-oriented and partly regex-friendly
Markdown's inline patterns (**bold**, *italic*, `code`, [link](url)) match well with regex. Block patterns (lists, blockquotes, code fences) are line-by-line state. Real Markdown parsers handle all of it correctly.
Bold and italic
Bold: \*\*([^*]+)\*\*
Italic: \*([^*]+)\*
Watch the order — if you process bold first, italic patterns won't accidentally consume **.
Inline code
`([^`]+)`
Backticks bracketing non-backtick content. For code that contains backticks, real Markdown uses double backticks (``code with `backticks` inside``) — handle if needed.
Links
\[([^\]]+)\]\(([^)]+)\)
Captures link text in group 1, URL in group 2. Doesn't handle nested brackets or images () — add !? at the start for that.
Headings
Line-anchored: ^(#{1,6})\s+(.+?)\s*$ with MULTILINE. Captures level (number of #) in group 1, text in group 2.
The right tool: a real parser
For converting Markdown to HTML, processing nested lists, or anything beyond ad-hoc rewrites, use a real parser: Python markdown or mistune, JS marked, Rust pulldown-cmark. Regex is for spot fixes and lightweight transformations.