Skip to content

Instantly share code, notes, and snippets.

View Jimmant91's full-sized avatar

James Antley Jimmant91

  • Technica Editorial Services
  • Raleigh, NC
View GitHub Profile
@Jimmant91
Jimmant91 / tutorial.md
Last active August 11, 2021 09:27
Regex Tutorial

Regex Tutorial: Matching an HTML Tag

A regex, which is short for regular expression, is a sequence of characters that defines a specific search pattern. When included in code or search algorithms, regular expressions can be used to find certain patterns of characters within a string, or to find and replace a character or sequence of characters within a string. They are also frequently used to validate input.

Summary

This Regex tutorial will breakdown the regular expression that can be used to search for tags, and potentially extract the data, in an HTML document, using the following string of code:

/^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/