Markdown to Plain Text - Problem

Convert basic Markdown text to plain text by removing all formatting symbols and extracting the content.

The input contains common Markdown elements:

  • Headers: # Header 1, ## Header 2, etc.
  • Bold: **bold text** or __bold text__
  • Italic: *italic text* or _italic text_
  • Links: [link text](url)
  • Lists: - item or * item or 1. item

Return the plain text content with proper spacing and line breaks preserved.

Input & Output

Example 1 — Basic Formatting
$ Input: markdown = "# Hello **world**"
Output: Hello world
💡 Note: Header marker '#' is removed, bold markers '**' are removed, keeping the plain text content
Example 2 — Links and Lists
$ Input: markdown = "Visit [Google](https://google.com)\n- Item 1"
Output: Visit Google\nItem 1
💡 Note: Link '[Google](https://google.com)' becomes 'Google', list marker '- ' is removed
Example 3 — Mixed Formatting
$ Input: markdown = "## *Important* __note__"
Output: Important note
💡 Note: Header '##', italic '*', and bold '__' markers are all removed, leaving clean text

Constraints

  • 1 ≤ markdown.length ≤ 104
  • Input contains only valid Markdown syntax
  • Formatting markers are properly paired

Visualization

Tap to expand
Markdown to Plain Text ConversionINPUT MARKDOWN# Hello **world**[Google](https://google.com)- Item 1*italic* textRaw markdown withformatting symbolsALGORITHM STEPS1Remove header markers (#)2Strip bold/italic (**,*,__,_)3Extract link text [text](url)4Remove list markers (-, *, 1.)Pattern matching withregular expressionsFINAL RESULTHello worldGoogleItem 1italic textClean plain textoutput readyKey Insight:Pattern recognition allows us to transform markdown formatting in a single pass,extracting content while preserving text structure and readability.TutorialsPoint - Markdown to Plain Text | Pattern Matching Approach
Asked in
Microsoft 35 GitHub 28 Stack Overflow 22 Slack 18
23.4K Views
Medium Frequency
~15 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen