Last active
November 29, 2019 19:09
-
-
Save Shimmermare/6d0548af59982649f14468893feb3153 to your computer and use it in GitHub Desktop.
Regex for matching HTML tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!!! DON'T USE REGEX TO PARSE HTML UNLESS YOU ABSOLUTELY HAVE TO !!! | |
Match full tag: <\s*(\w+)(?:\s*\w+=(?:"[^"]*"|'[^']*'))*?\s*>(.*?)<\s*\/\s*\1\s*> | |
Group 1: tag name | |
Group 2: tag content | |
! Uses repeated captures, thus isn't supported by Python's re - use this https://pypi.org/project/regex/ ! | |
Match self-closing tag: <\s*(\w+)(?:\s*\w+=(?:"[^"]*"|:'[^']*'))*?\s*\/\s*> | |
Group 1: tag name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment