In every article or question I've seen quite a lot, just use:
str.replace(/yourstring/g, 'whatever');
But I want to use a variable instead of "yourstring". Then people say just use new RegExp(yourvar, 'g') . The problem is that yourvar may contain special characters, and I don't want it to be treated like a regular expression.
So how do we do it right?
Input Example:
'ab'.replaceAll('.','x')
Required Conclusion:
'axbx'
source share