I'm trying to replace every word in a text for another but couldn't find any of for doing that.
Like this example:
from this> hi my name is Robert.
to this> ligh ligh ligh ligh ligh (same amount of words)
Can someone help me? Thanks in advance.
I'm trying to replace every word in a text for another but couldn't find any of for doing that.
Like this example:
from this> hi my name is Robert.
to this> ligh ligh ligh ligh ligh (same amount of words)
Can someone help me? Thanks in advance.
Just use String.prototype.replace
:
var from = 'hi my name is Robert.';
var to = from.replace(/([a-zA-Z]+)/g, 'ligh');
// or use `[a-zA-Z0-9]` if you want to allow numbers in a word
var to2 = from.replace(/([a-zA-Z0-9]+)/g, 'ligh');
console.log(to);