美文网首页
JS使用正则表达式获取小括号、中括号及花括号

JS使用正则表达式获取小括号、中括号及花括号

作者: 啵崽崽 | 来源:发表于2020-04-23 09:45 被阅读0次
        var str="123{xxxx}456[我的]789123[你的]456(1389090)789";
        var regex1 = /\((.+?)\)/g;  // () 小括号
        var regex2 = /\[(.+?)\]/g;  // [] 中括号
        var regex3 = /\{(.+?)\}/g; // {} 花括号,大括号
        // 输出是一个数组
        console.log(str.match(regex1)); 
        console.log(str.match(regex2));
        console.log(str.match(regex3));

相关文章

网友评论

      本文标题:JS使用正则表达式获取小括号、中括号及花括号

      本文链接:https://www.haomeiwen.com/subject/fpdxwhtx.html