JSFiddle - React, Tailwind, and code Playground

HTML

<textarea id="id_src">word0 "str \"word1\\\"word'2 word3 word4" word5 12345 word6 "str 56 word7" /regex "e56757546/gim 35 '64e word8" 674 64' 47 6457</textarea><br /><br />
<input type="button" id="id_btn" value="Replace" /><br /><br />
<textarea id="id_dest"></textarea>

CSS

textarea {
  width: 90%;
  min-height: 100px;
}

JavaScript

function replace(str) {
  var regex = /(["'/])(.*?[^\\])??(?:\\\\)*\1[gim]*|\b[a-z_][0-9a-z_]*\b/g;
  var m, words = [];
  while ((m = regex.exec(str)) != null) {
    if (!m[1]) {
      words.push(m.index, regex.lastIndex);
    }
  }
  var removed = Math.floor(Math.random() * words.length / 2);
  alert(str.substring(words[removed * 2], words[removed * 2 + 1]));
  return str.substr(0, words[removed * 2]) + str.substr(words[removed * 2 + 1]);
}

//-----------------------------------------------------------------
document.getElementById('id_btn').onclick = function() {
	var src = document.getElementById('id_src');
  var dest = document.getElementById('id_dest');
  dest.value = replace(src.value);
};