preg_match in JavaScript?

后端 未结 8 1958
逝去的感伤
逝去的感伤 2020-12-08 13:17

Is it possible in JavaScript to do something like preg_match does in PHP ?

I would like to be able to get two numbers from str

8条回答
  •  醉话见心
    2020-12-08 13:31

    var myregexp = /\[(\d+)\]\[(\d+)\]/;
    var match = myregexp.exec(text);
    if (match != null) {
        var productId = match[1];
        var shopId = match[2];
    } else {
        // no match
    }
    

提交回复
热议问题