Copy code code as follows: var s = "Abachdas"; var s2 = s.replace (new regexp (/(a)/), 'b'); // Replace all A in s to B