1

After loading the document the \n\g has to be removed. I am trying with this code, for any text its working fine but for this characters \n\g it's not working

$("document").ready(function() {
  document.body.innerHTML = document.body.innerHTML.replace(/\n\g/g, 'n');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>here is that we are @ replacing "\n\g" "\n\g"
  <div>here is that we are replacing</div>
</div>"\n\g"
<div>here is another @ that we are "\n\g" replacing</div>
<p>here is another @ that we are replacing</p>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
kvimalkr55
  • 53
  • 8

2 Answers2

0

You have to escape the \ character in your regex otherwise it's just treated as a literal \.

document.body.innerHTML = document.body.innerHTML.replace(/\\n\\g/g, 'n');
mcon
  • 679
  • 6
  • 22
0

You are almost there. You just need to escape \n in regular expression with extra \\n and similarly \g. To remove double quotes escape with \"

$("document").ready(function() {
  document.body.innerHTML = document.body.innerHTML.replace(/\"(\\n\\g)\"/g, '');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>here is that we are @ replacing "\n\g" "\n\g"
  <div>here is that we are replacing</div>
</div>"\n\g"
<div>here is another @ that we are "\n\g" replacing</div>
<p>here is another @ that we are replacing</p>
freedomn-m
  • 27,664
  • 8
  • 35
  • 57
Dinesh undefined
  • 5,490
  • 2
  • 19
  • 40