简体   繁体   中英

How to remove any string inside square brackets

我从http://ar.wikipedia.org复制了一些包含[15],[89]等的段落。我希望我们使用JavaScript或jQuery自动删除其中包含任何内容的[]。

Try this regular exp.

test = "[5] new value";    
test = test.replace(/\[(.+?)\]/, '$1');
alert(test);

Update

test = "FIFA publishes its results according to IFRS. The total compensation for the management committee in 2011 was 30 million for 35 persons. Blatter, the only full time, earns approx 2 Mio CHF, 1.2 Mio fix, the rest bonus.[4][5][6]";
test = test.replace(/\[(.+?)\]/g, '$1');//for global replace
alert(test);

Updated Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM