r6b4xg
Last Updated: February 25, 2016
·
3.079K
· gnclmorais

Regex to match GitHub’s Markdown code blocks

In a quest to fix a small issue on wtf.js, I struggled on the web for a few hours until I got a regular expression good enough for my purpose: match GitHub’s Markdown code blocks, which means code inside tags like ```.

/```[a-z]*\n[\s\S]*?\n```/g

The expression above is able to do the following (green highlights are matches):
Picture

Image courtesy of Refiddle.

2 Responses
Add your response

17842

I think you hit an issue displaying your regex. Coderwall interpreted part of your regex as a code snippet and removed an important piece!

over 1 year ago ·
17845

You are totally right, thank you! I had to change the post a bit, in order to render the regex correctly… Again, thank you!

over 1 year ago ·