Haha, welp.
I wrote this. Try to see what's wrong.
If fed "> foobar <", this runtimes after making a huge string, and BYOND doesn't seem to free the memory, so the server is basically done for.
You might be able to fix your one by constraining the search for the ">" token to after the start of the "<". But the basic way to do it is to copy all chars to from the input one at a time to your output, and basically throw away characters found after you find a "<". Then, if you're in that state and find a ">" you switch back to state 1.
So your have two states, which can be represented as two nested while loops. The most basic form of the algorithm is thus:
While (not end-of-input)
scan char
if (char <> "<")
append char to output
else
while (char <> ">" AND not end-of-input)
scan char
end while
end if
end while
Both algorithms would have a problem if e.g. there was a string inside a tag with a greater-than symbol in it, e.g. javascript on an element which adds a tag, or a comparison which uses the > symbol. So to be totally legit you'd need to also scan the inside of each tag for strings delimited with ' and ", and ignore ">" symbols if they're inside a pair of quotes:
While (not end-of-input)
scan char
if (char <> "<")
append char to output
else
while (char <> ">" AND not end-of-input)
scan char
if (char == single-quotes)
do
scan char
while (char <> single-quotes AND not end-of-input)
else if (char == double-quotes)
do
scan char
while (char <> double-quotes AND not end-of-input)
end if
end while
end if
end while
should work perfectly even for cases where there was a tag or > inside a string in a tag.