I try to write a simple Markdown parser in JavaScript. Therefore I want to check for the [link content][link id] syntax. I use the following code:
[link content][link id]
Because the first argument of the RegExp constructor is a string, not a pattern literal, you have to escape the backslashes, since you want literal backslashes in the pattern:
var r = new RegExp( '\\[(.*?)\\][ ]*\\[([0-9]+)\\]', 'g' );