DEV Community

loading...

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

Haider Ali Punjabi
Learner. Pursuing Integrated Masters in Computer Applications
・1 min read

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 ?

Discussion (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 Author

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