Skip to content

Instantly share code, notes, and snippets.

@jserrao
Created September 7, 2016 14:18
Show Gist options
  • Save jserrao/833fb0dfc90089db299b15c9e62b454b to your computer and use it in GitHub Desktop.
Save jserrao/833fb0dfc90089db299b15c9e62b454b to your computer and use it in GitHub Desktop.
Basic regex for HTML
// All regex start and with forward slashes
/(conditions-here)/
// Put g character at end of regex to get recursion
/(conditions-here)/g
// Matches all opening HTML tags
/(<\w+\b>)/g
// Matches all <a href="anything">
/(<a\shref=".*">)/g
// Matches any word
/(\w+\b)/g
// Matches any closing HTML tag </a></li></ul>
/(<\/\w+\b)>)/g
// Matches all opening and closing tags without attributes
/(<)((\w+\b)|(\/\w+\b)|)(>)/g
// Regex that combs through opening and closing HTML tags, <a href="whatever.html"
/((<\w+\b>)|(<a\shref=".*">)|(\w+\b)|(<\/\w+\b)>)/g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment