r6b4xg
Last Updated: February 25, 2016
·
1.682K
· gnclmorais
C740358b2cce341557a23ffb981aacf2

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.

Say Thanks
Respond

2 Responses
Add your response

17842
1973614 10152332782865736 8196949058027341535 o copy

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
C740358b2cce341557a23ffb981aacf2

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 ·