正则表达式 获取括号内的内容

时间:2019-12-13 12:14:46   收藏:0   阅读:87

https://blog.csdn.net/genius_yym/article/details/79670035

JS 正则表达式 获取小括号 中括号 花括号内的内容

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

JAVA

regex = "(?<=\\[)(\\S+)(?=\\])"
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!