JavaScript - replace square brackets in a string

Viewed 5522

I have a simple string and trying to convert [~sample] to @sample. For example:

var string = 'Completely engineer client-based strategic [~theme] areas before cross [~media] technology';
string.replace('[~', '@');

I have tried above solution but it only convert the first one and the ] can not be removed.


now I learnt how to use /g

6 Answers
Related