如何删除方括号内的任何字符串

时间:2014-06-19 11:58:35

标签: javascript

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

1 个答案:

答案 0 :(得分:0)

试试这个常规exp。

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

更新

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