Skip to content

Instantly share code, notes, and snippets.

@webstrand
Created August 12, 2024 16:53
Show Gist options
  • Save webstrand/afdf012c03f96359893fb1dcd9ff4814 to your computer and use it in GitHub Desktop.
Save webstrand/afdf012c03f96359893fb1dcd9ff4814 to your computer and use it in GitHub Desktop.
(?(DEFINE)
(?<S>[\x20\x9\xD\xA]+)
(?<NameStartChar>[A-Za-z:_\xC0-\xD6\x{D8}-\x{F6}\x{F8}-\x{2FF}\x{370}-\x{37D}\x{37F}-\x{1FFF}\x{200C}-\x{200D}\x{2070}-\x{218F}\x{2C00}-\x{2FEF}\x{3001}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFFD}\x{10000}-\x{EFFFF}])
(?<NameChar>(?&NameStartChar)|[\-\.0-9\x{B7}\x{0300}-\x{036F}\x{203F}-\x{2040}])
(?<Name>(?&NameStartChar)(?&NameChar)*)
(?<EntityRef>&(?&Name);)
(?<PercRef>%(?&Name);)
(?<Reference>(?&EntityRef)|(?&PercRef))
(?<AttValue>"(?:[^<&"]|(?&Reference))*"|'(?:[^<&']|(?&Reference))*'|[^"'`=<>\x20\x9\xD\xA]+)
(?<Attribute>(?&Name)(?:=(?:(?&AttValue))?)?)
(?<STag>\<(?&Name)(?:(?&S)(?&Attribute))*(?&S)?\>)
(?<ETag>\<\/(?&Name)>)
(?<Content>[^<]*)
(?<TagPair>\<((?&Name))(?:(?&S)(?&Attribute))*(?&S)?\>(?&HTML)*\<\/\g{-1}>)
(?<TagSingle>\<(?&Name)(?:(?&S)(?&Attribute))*(?&S)?\/\>)
(?<HTML>(?&TagPair)|(?&TagSingle)|(?&Content))
)
(?&HTML)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment