-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathKey.regex.ps1
More file actions
49 lines (47 loc) · 1.27 KB
/
Copy pathKey.regex.ps1
File metadata and controls
49 lines (47 loc) · 1.27 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
<#
.SYNOPSIS
Matches a YAML key
.DESCRIPTION
Matches a YAML key. The -Key can be customized.
.EXAMPLE
Get-Module Irregular |
Split-Path |
Get-ChildItem -Recurse -Force -Filter *.yml |
?<YAML_Key> -Key uses -IncludeInputObject |
Foreach-Object {
$_.InputObject |
?<YAML_Value> -Text $y -StartAt $_.Index -Count 1
}
#>
param(
# The key to match. By default, this is any key.
[string]
$Key = '[^\:]+'
)
[Regex]::new(
$(
<#?<
New-RegEx -Description "Matches a YAML key" -Modifier Multiline -StartAnchor LineStart -Comment 'A key starts off a line' |
New-RegEx -CharacterClass Whitespace -Min 0 -Comment 'Followed by whitespace' -Name Indent |
New-Regex -Name InList (
New-RegEx -LiteralCharacter '-' |
New-RegEx -CharacterClass Whitespace
) -Optional -Comment 'Followed by an optional list start'
>#>
@'
# Matches a YAML key
(?m)^ # A key starts off a line
(?<Indent>\s){0,} # Followed by whitespace
(?<InList>\-\s)? # Followed by an optional list start
'@ +
[Environment]::NewLine +
$Key +
[Environment]::NewLine
<#?<
New-RegEx -LiteralCharacter ':' -Comment 'Followed by colon'
>#>
@'
\: # Followed by colon
'@
),'IgnoreCase,IgnorePatternWhitespace','00:00:01'
)