JSFiddle - React, Tailwind, and code Playground

by gaby de wilde

JavaScript

function stripHTML(my_string){
        charArr   = my_string.split('');
        resultArr = [];
        htmlZone  = 0;
        quoteZone = 0;
        for( x=0; x < charArr.length; x++ ){
         switch( charArr[x] + htmlZone + quoteZone ){
           case "<00" : htmlZone  = 1;break;
           case ">10" : htmlZone  = 0;resultArr.push(' ');break;
           case '"10' : quoteZone = 1;break;
           case "'10" : quoteZone = 2;break;
           case '"11' : 
           case "'12" : quoteZone = 0;break;
           default    : if(!htmlZone){ resultArr.push(charArr[x]) }
         }
        }
        return resultArr.join('')
    }
    
    alert(stripHTML(prompt('provide your string','<a href="banana>bar" dataset=\'a>b\'>foobar</a>das <br>fh asjflasjfhsl')))