Skip to content

Instantly share code, notes, and snippets.

View FatherDkay's full-sized avatar

Paul D Bailey FatherDkay

View GitHub Profile

Using RegEx to Validate an HTML Tag

RegEx (or regular expression) is a powerful tool that can be used to verify, validate, or find parts of a string or text. One of the most amazing things about RegEx is it's flexibility and cross platform usage. RegEx isn't limited to programming language such as JavaScript or C#; it can be used with almost any application.

Summary

This tutorial will demonstrate how to use regex to match an html tag. The actual regex code is /^<([a-z]+)([^<]+)(?:>(.)</\1>|\s+/>)$/ That may look confusing, but once it's broken down into it's components, you will see it's easy and powerful.

Table of Contents