0

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
  • 319,460
  • 37
  • 290
  • 318
kvimalkr55
  • 43
  • 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
  • 21
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
  • 24,983
  • 7
  • 32
  • 55
Dinesh undefined
  • 5,362
  • 2
  • 17
  • 39