JSFiddle - React, Tailwind, and code Playground
JavaScript
const search = '+';
const searchRegExp = new RegExp(search, 'g'); // Throws SyntaxError
const replaceWith = '-';
const result = '5+2+1'.replace(searchRegExp, replaceWith);
const search = '+';
const searchRegExp = new RegExp(search, 'g'); // Throws SyntaxError
const replaceWith = '-';
const result = '5+2+1'.replace(searchRegExp, replaceWith);