I know my question might look like a duplication for this question, but its not
I am trying to match a class name inside html text that comes from the
Regular expressions are not a good fit for parsing HTML. HTML is not regular.
jQuery can be a very good fit here.
var html = 'Your HTML here...';
$('' + html + '').find('[class~="b"]').each(function () {
console.log(this);
});
The selector [class~="b"]
will select any element that has a class
attribute containing the word b
. The initial HTML is wrapped inside a div
to make the find
method work properly.