-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRegion.regex.ps1
More file actions
34 lines (31 loc) · 735 Bytes
/
Region.regex.ps1
File metadata and controls
34 lines (31 loc) · 735 Bytes
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
<#
.Synopsis
Matches a PowerShell Region
.Description
Matches a PowerShell #region/#endregion pair. Returns the Name of the Region and the Content.
#>
param(
[Parameter()]
[string]
$RegionName = $(
'(?:.|\s)+?(?=\z|\s{0,}$)' # Matches anything until whitespace and the end of line.
# This prevents trailing whitespace from failing to pair the match, but allows whitespace within the region name
)
)
if ($PSBoundParameters['RegionName']) {
$RegionName = $RegionName -replace '\s', '\s'
}
@"
(?m)
^\s{0,} # Line start and whitespace
\#region # The literal 'region'
\s{1,}
(?<Name>$RegionName)
(?<Content>
(?:.|\s)+?(?=
\z|
^\s{0,}\#endregion\s\k<Name>
)
)
^\s{0,}\#endregion\s\k<Name>
"@