Say I had the following string:
var str = '(1 + foo + 3) / bar';
And I want to replace all strings just with the letter 'x'. I tried:
str = str.replace(/\w/g, 'x');
This results in:
(x + xxx + x) / xxx
Instead, I would like the result to be:
(1 + x + 3) / x
How would I do this? How would I find just the words that don’t have digits and replace the word to a single letter?
Why not just use
[a-z]+instead of\w? (Make sure to add the case-insensetive flag, or use[a-zA-Z]instead)