DEV Community

Haider Ali Punjabi
Haider Ali Punjabi

Posted on

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

I just found out after one of my friends couldn't access my NextJS web app. Finished my free trial of BrowserStack on it.

Can I Use replaceAll ?

Top comments (3)

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
Collapse
 
fawazahmed0 profile image
Fawaz Ahmed

yeah, i faced the same problem few days back, ended up using replace with g flag

Collapse
 
haideralipunjabi profile image
Haider Ali Punjabi

Hmm I used the .split().join() method