JSFiddle - React, Tailwind, and code Playground

by dmitri_pavlutin

JavaScript

const search = '\\+';

const searchRegExp = new RegExp(search, 'g'); // Throws SyntaxError
const replaceWith = '-';

const result = '5+2+1'.replace(searchRegExp, replaceWith);

console.log(result)