title: How can I match a Markdown code block with RegEx?
body: <p>I am trying to extract a <code>code block</code> from a Markdown document using PCRE RegEx. For the uninitiated, a code block in Markdown is defined thus:</p>
  
  <blockquote>
    <p>To produce a code block in Markdown, simply indent every line of the
    block by at least 4 spaces or 1 tab.
    A code block continues until it reaches a line that is not indented (or the end of the article).</p>
  </blockquote>
  
  <p>So, given this text:</p>
  
  <pre><code>This is a code block:
  
      I need capturing along with
      this line
  
  This is a code fence below (to be ignored):
  
  ``` json
  This must have three backticks
  flanking it
  ```
  
  I love `inline code` too but don't capture
  
  and one more short code block:
  
      Capture me
  </code></pre>
  
  <p>So far I have this RegEx: </p>
  
  <pre><code>(?:[ ]{4,}|\t{1,})(.+)
  </code></pre>
  
  <p>But it simply captures each line prefixed with at least four spaces or one tab. It doesn't capture the whole block.</p>
  
  <p>What I need help with is how to set the condition to <em>capture everything after 4 spaces or 1 tab until you either get to a line that is not indented or the end of the text</em>.</p>
  
  <p>Here's an online work in progress:</p>
  
  <p><a href="https://www.regex101.com/r/yMQCIG/5" rel="nofollow noreferrer">https://www.regex101.com/r/yMQCIG/5</a></p>