Need Help Creating a Javascript REGEX To Match HTML Tags and Properties

I would like to create a pattern that matches HTML markups with properties where the values of all properties should start with a letter followed by alpha numeric characters. Some properties should have names that contain a hyphen and the Class property should be able to contain multiple values separated by an empty space.

The following is the REGEX pattern I have created and it matches any string containing HTML markups which has zero or more properties with names and values that can consist of only alpha numeric characters and hyphens. However, I’m struggling to come up with a pattern that matches what I’ve described above.

<([a-z-]+)\s?[a-z-="\s?]*\/?>(\n?.*\n?<\/\1>)?

I don’t have anything useful to add here other than a warning against using regex to match with HTML.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.