-2

我有这样的字符串:Stackoverflow is a useful Forum for [all][people][over the world] and I like this rum

我想从上面的字符串中获取文本以获得结果:

text1 = "all";

text2 = "people";

text3 = "over the world";
4

1 回答 1

2

干得好:

var str = 'Stackoverflow is a useful Forum for [all][people][over the world] and I like this rum';
var matches = str.match(/\[.*?]/g);
console.log(String(matches[0]).replace( /(^.*\[|\].*$)/g, '' ));
console.log(String(matches[1]).replace( /(^.*\[|\].*$)/g, '' ));
console.log(String(matches[2]).replace( /(^.*\[|\].*$)/g, '' ));

演示

于 2013-10-23T20:07:49.720 回答