Regular expression to get number between two square brackets

前端 未结 6 1677
死守一世寂寞
死守一世寂寞 2021-01-27 14:19

Hi I need to get a string inside 2 pair of square brackets in javascript using regular expressions.

here is my string [[12]],23,asd

So far what I tr

6条回答
  •  走了就别回头了
    2021-01-27 14:43

    If you need to get 12 you can just use what you mentioned with a capturing group \[\[(\d+)\]\]

    var myRegexp= /\[\[(\d+)\]\]/;
    var myString='[[12]],23,asd';
    var match = myRegexp.exec(myString);
    console.log(match[1]); // will have 12
    

提交回复
热议问题