Below is some string, which should be serve as my HTML-Code.
I am trying from below string or HTML-Code separate the HTML-Tagname. After processing on the string the result should be something like as follows: =div=div=strong=em=p=b=p=p=h4=h1=span=
.
Here is my HTML-Code in the variable "sTagName":
var sTagName = 'abc<div style="left:100px;" > some <div>MyText, <strong> hgz uz <em> Some text for flrdm <p><b>b, <p> <p><h4><h1><span id="MySpan">any text, ';
Here is my solution:
// Remove all attributes, e.g. <div style="left:100px;" > will be converted to <div>
sTagName = sTagName.replace(/<([a-zA-Z0-9]+).*?>.*?/g, '<$1>' );
// I add the "<>" at end of HTML-Code in order to remove the last useless string, I mean "Any text, "
sTagName = sTagName + "<>";
sTagName = sTagName.replace(/.*?<(.*?)>.*?/g,'=$1');
alert(sTagName);
The function alert(sTagName)
delivers the expected result.
But I want improve my method referring to performance. E.g. I would like to build from two RegEx one RegEx, or something like that.
Any idea? Thanks in advance.