Regex match markdown link

The accepted answer matches bold tags * and headings ###. Marvin's fix matches weird groups of text if you have more than one bracket pair on a line. (e.g. [word] a [link](url))

This regex fixes that:

.replace(/\[([^\[\]]*)\]\((.*?)\)/gm, '$1')

Note that URLs with bracket pairs in them will need to be URL encoded


This regex will match markdown text following the [some reference text](some url) pattern - and includes two groups containing the values of both the reference text and the url.

\[([^\]]+)\]\(([^)]+)\)

If you want, you can just simply replace the markdown text with reference text in the original string.


Thomas's answer above can match headings with ### and bold tags *. To avoid matching those use the following regex instead:

.replace(/([])|\[(.*?)\]\(.*?\)/gm, '$1')

Might be useful for those using javascript/node to match link pattern on markdown.


I came up with this regex:

(?:__|[*#])|\[(.*?)\]\(.*?\)

var str = '# This is the title. ## This is the subtitle. **some text** __some more text__. [link here](http://google.com)'

document.write(String(str).replace(/(?:__|[*#])|\[(.*?)\]\(.*?\)/gm, '$1'));