-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGetMarkupTag.regex.ps1
37 lines (35 loc) · 1.29 KB
/
GetMarkupTag.regex.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<#
.Synopsis
Gets markup tags
.Description
Gets one or more specific markup tags. By default, anchor tags.
#>
param(
[Parameter(ValueFromRemainingArguments=$true)]
[string[]]$Tag = @('a')
)
@"
\< # The tag Start
(?<TagName>$($Tag -join '|')) # 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>>)
)
)
"@