DEV Community

loading...

Discussion on: Friendly reminder: String.replaceAll is only supported on 83.7% of devices

Collapse
maciejtrzcinski profile image
Maciej Trzciński 🌱🇵🇱 • Edited

Hi,
You can use RegExp with replace, all browsers support: caniuse.com/?search=RegExp
/

const searchRegExp = new RegExp('\\+', 'g'); 
const result = '5+2+1'.replace(searchRegExp, '-');
console.log(result) // 5-2-1
Enter fullscreen mode Exit fullscreen mode