JavaScript RegExp objects

前端 未结 5 1314
情话喂你
情话喂你 2020-12-07 03:51

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:



        
5条回答
  •  自闭症患者
    2020-12-07 04:24

    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' );
    

提交回复
热议问题