-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTag.regex.txt
24 lines (24 loc) · 1.07 KB
/
Tag.regex.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# This will match a balanced markup tag.
\< # The tag Start
(?<TagName>\w+) # The name of the Tag is any non number of non-word characters
(?<TagAttributes> # It's attributes are
.+? # anything until
(?= # the close of the tag.
(?> # The close of the tag can be either (IsClosed)/> or (IsOpen)>
(?<IsClosed>/>)|(?<IsOpen>>)
)
)
)
(?(IsOpen)(?: # If the tag was open
> # match the end tag (so that it's not captured as TagContent)
(?<TagContent> # then capture the tag content
(?>
(.|\s)+?(?!<\k<TagName>)|
(?=\<\k<TagName>)(?<TagDepth>)|
(?=\<\/\k<TagName>)(?<-TagDepth>)
)*(?(TagDepth)(?!))
# It is anything until
)(?=\<\/\k<TagName>) # the closing tag
(?:\<\/\k<TagName>>)
)
)