Alas, I do not know javascript, so I wrote an example in Ruby:
str = <<'EOT' ΠΡΠΎ <!--ΠΏΡΠΈΠΌΠ΅Ρ ΡΠ΅ΠΊΡΡΠ°--> Ρ <a href="#">ΠΊΠ°ΠΊΠΎΠΉ-ΡΠΎ</a> <br>ΡΠ°Π·ΠΌΠ΅ΡΠΊΠΎΠΉ <br /> <b class="11">ΠΈ</b> <amg src="1"> <area>Π½Π΅ΠΏΠ°ΡΠ½ΡΠΌΠΈ</area> <strong> ΡΠ΅Π³Π°ΠΌΠΈ</strong> ΠΈ, <!--ΠΊΠΎΠΌΠ΅Π½ΡΠ°ΠΌΠΈ-->, <ul id="w"> <li id="id" class="class">1</li></ul>. <u class="Π½Ρ ΠΈ Π΄Π°ΠΆΠ΅ ΡΠ°ΠΊ" /> EOT puts str.gsub(/(<(?!\/?a\b)(?!\/?b\b)(?!\/?i\b)(?!\/?u\b)(?!\/?ul\b)(?!\/?li\b)(?!\/?ol\b)(?!\/?img\b)[^>]+\s*\/?>)/m,'') .gsub(/(<a\b|b\b|i\b|u\b|ul\b|li\b|ol\b|img\b)(\s[^>]+?)(\s*\/?>)/m,'\\1\\3')
Result:
ΠΡΠΎ Ρ <a>ΠΊΠ°ΠΊΠΎΠΉ-ΡΠΎ</a> ΡΠ°Π·ΠΌΠ΅ΡΠΊΠΎΠΉ <b>ΠΈ</b> Π½Π΅ΠΏΠ°ΡΠ½ΡΠΌΠΈ ΡΠ΅Π³Π°ΠΌΠΈ ΠΈ, , <ul> <li>1</li></ul>. <u />
Eventually
The first global replacement regexp removes all tags not from a white sheet:
/(<(?!\/?a\b)(?!\/?b\b)(?!\/?i\b)(?!\/?u\b)(?!\/?ul\b)(?!\/?li\b)(?!\/?ol\b)(?!\/?img\b)[^>]+\s*\/?>)/m,''
The second regexp cleans tags from the white sheet:
/(<a\b|b\b|i\b|u\b|ul\b|li\b|ol\b|img\b)(\s[^>]+?)(\s*\/?>)/m,'\\1\\3'
Online at ideone
Thus, program cycles are not needed, all can regexps themselves :)
Ps. Naturally, if the register is not important - in the regexp add my qualifier "i"