instead of var address = obfuscated[1] .replace(' AT ', '@') .replace(' DOT ', '.') .replace(/^\s+|\s+$/g, '');
try var address = obfuscated[1] .replace(' AT ', '@') .replace(new RegExp(’ DOT ‘, ‘g’), ‘.’) .replace(/^\s+|\s+$/g, ''); It wasn't getting rid of all the dots if it was mydomain.com.au. Will probably cause problems if a dot is used before the @ symbol though.