Q:

JavaScript regex replace string characters

I'd like to learn how to replace string?
I have an email address someone@website.com how do I replace @ to % and . to ±

A:

var replacements = {"@": "%", ".": "±"};
string.replace(/@|\./, function (match) {
    return replacements[match];
});

