I have a string:
"josh marie anne josh anne marie chloe josh anne ..."
If I found josh, I want to replace for JJJ. So I have a string replace like this:
var p = 'josh';
var username = 'JJJ';
$("#comment").val($("#comment").val().replace(p, username));
the problem is, I don't want to replace the first josh
in the string... I want to choose with one to replace (the second josh in the #comment
or the first josh, of the third...)
Any ideas how to choose with one to replace?
html
<textarea id=comment>josh marie anne josh anne marie chloe josh anne josh marie anne josh anne marie chloe josh anne</textarea>