0

I need to trim a space after '[' and before ']'.

To trim a space after '[', String.replace(/\[ /g, '['); works;

however, to trim a space before ']', String.replace(/ \]/g, ']'); seems not working.

What is the proper regex for that?

JavaScript.

4

1 回答 1

1

你可以试试这个:

 str = str.replace(/\s+(\])|(\[)\s+/g, '$1$2');
于 2013-07-27T23:12:54.830 回答