I have the following javascript code:
var texto = "<div class='hola'> content </div>"+
"<div class='mundo'> </div>";
var classRE = /class=[\'|"](\w+)[\'|"]/;
console.log(classRE.exec(texto));
I would like the regular expression to return all classes present in text. I managed to get it to return only the class in the first div but I would like to also receive those in the second div, and all those that may exist. I am new with ER. I really appreciate her help. Thanks.
It is not the best way but I have done this with Jquery and at least if it is not very efficient it is effective
And your classes in the Sun
Result of console.log():
I would recommend you not to use regular expressions to parse HTML. Although possible, it is not recommended.
Effectively your input is text , but you can convert it to html nodes and then process them with javascript.
To achieve this you can create an html element and insert inside with innerHTML the nodes you want to parse.
For example:
You can then use javascript to get the classes.
For example, you could do something like this: