JSFiddle - React, Tailwind, and code Playground

by Diana Lemen

JavaScript

var string = "<html> <head> </head> <body> <a>This is a tagt 2</a> <p>This is paragraph1</p> <a>This is Assigntment 2</a> <p>This is paragraph1</p> <div> <img> </img> </div> <body> </html>";


var re = /^(?:html|head|body|a|p|div|input|link|meta|param)$/i
var m;
var HashTable = {};

do {
    // conduct the match 
    m = re.exec(string);

    // verify the match was successful
    if (m) {
        // verify the HashTable has an entry for the found tag name
        if ( !(m[1] in HashTable) ) {
            // no entry was found so we'll add the entry for this tag name and count it as zero
            HashTable[m[1]] = 0
        } // end if

        // increment the tag name counter
        HashTable[m[1]] ++
    } // end if 
} while (m);

console.log("")
// output the number of all found tag names
for (var key in HashTable) {
    console.log(key + "=" + HashTable[key]);
}

alert( m = re.exec(string))