How to replace a Regular expression — a regular expression?

There is a function:
function chistka() {
 var s = document.getElementById('k2').value;
 var ri = /(>)\s(<)/gmi;
 var re = /$1\n$2/;

 var result = s.replace(ri, re);
 document.getElementById('k2').value = result;
}
Requirement: to Translate the text when in HTML there are spaces between the tags/symbols ">" and "<"

Example: Find "> <"and to replace ">*newline*<"

The problem is that the replacement turns out "/>\n< /" that is recognized as text and not as a regular expression.

The result:
<style type="text/css">\n</!-- span.cls_004{font-family:Arial,serif;font-size:18.1 px;color:rgb(255,255,255);font-weight:bold;font-style:normal;text-decoration: none} --/>\n<//style/>\n</div style="position:absolute;left:50%;margin-left:-306px;top:0px;width:612px;height:792px;border-style:outset;overflow:hidden"/>\n</div style="position:absolute;left:0px;top:0px"/>\n</img src="Utah motorcycleFactSheet2012_files/background1.jpg" width=612 height=792></div/>\n</div style="position:absolute;left:29.88 px;top:32.86 px" class="cls_004"><span class="cls_004">2012 Utah Crash Facts</span></div/>\n<//div></code></pre><br>
The code: <a href="http://codepen.io/mihail9575/pen/nfjAF">Tyk</a></style>
September 26th 19 at 11:46
3 answers
September 26th 19 at 11:48
Solution
The variable must be a string:
function chistka() {
 var s = document.getElementById('k1');
 var result = s.value.replace(/(>)\s(<)/gmi, '$1\n$2');
 s.value = result;
}

Thank you ALL!
Bravo, You gave the answer and I Lynn even bother to explain what the variable should be a string, and You noted your answer decision. - Luella_Nolan commented on September 26th 19 at 11:51
Both answers are correct, so I didn't want to offend anyone. Grateful for all the help.

You had "slashes" - they didn't need and noticed something extra "(\n)", I don't quite understand what it was... - elva68 commented on September 26th 19 at 11:54
about the slashes, Yes, wrong. Fixed. - Luella_Nolan commented on September 26th 19 at 11:57
or here or in the code of the regular season looked so var ri = /(>)\s(<)(\n)/gmi;. - sallie.Run commented on September 26th 19 at 12:00
It is possible that it was (in the code in codepen.io) ... I tried to "help". - elva68 commented on September 26th 19 at 12:03
You can mark more than one solution answer. - Vito_Doy commented on September 26th 19 at 12:06
September 26th 19 at 11:50
re should be a string. And why in the regular season (\n) I do not understand.
In General, I would have done so:
function chistka() {
 var s = document.getElementById('k2').value;
 var ri = />\s+
September 26th 19 at 11:52
var ri = /(>)\s(<)/gmi;
var re = '$1\n$2';

codepen.io/iiil/pen/hfgmo

Find more questions by tags HTMLJavaScript