A regular expression is compared to a string that matches the contents of [ * * * * * * ]

72 1

For example, [ 43255]gege [ 1343fdg_32]gew [ ge43 ] is similar to multiple strings that require a string that matches the [ ] and output the string. How to find matching data with regular expressio &. Code unlimited ~.

3 Answers

141 3

It's possible to get a.

[([^][]+)]

javascript :

var matchs ="[43255]gege[1343fdg_32]gew[ge43]".match(/[([^][]+)]/g);
for(var i=0; i<matchs.length; i++){
 var m =/[^[]]+/.exec(matchs[i])
 console.log(m[0])
}
148 2

The rules used are

[([^]]+)]

Javascript code:

jsvar str ="[43255]gege[1343fdg_32]gew[ge43]";
var re =/[([^]]+)]/g;
var myArray;
while ((myArray = re.exec(str))!== null) {
 console.info(myArray[1]);
}

输出:

43255
1343fdg_32
ge43
...