JSFiddle - React, Tailwind, and code Playground

HTML

<textarea id=comment>josh marie anne josh anne marie chloe josh anne josh marie anne josh anne marie chloe josh anne</textarea>

CSS

#comment{
  
  width:400px;
  height:200px;
  
}

JavaScript

var p = 'josh',username = 'JJJ',cnt = 0,replaceAt = 3;
var regEx = new RegExp(p,"g")

$("#comment").val($("#comment").val().replace(regEx,function(matchedString){
  return (++cnt == replaceAt) ? username : matchedString;
}));