Skip to content

Commit 4ecc77b

Browse files
Merge pull request #68 from StartAutomating/MoreUnixRegEx
More Unix Regular Expressions
2 parents 2f5307c + 7692db4 commit 4ecc77b

File tree

6 files changed

+211
-3
lines changed

6 files changed

+211
-3
lines changed

Irregular.psd1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.6.1'
2+
ModuleVersion = '0.6.2'
33
RootModule = 'Irregular.psm1'
44
Description = 'Regular Expressions made Strangely Simple'
55
FormatsToProcess = 'Irregular.format.ps1xml'
@@ -15,6 +15,12 @@
1515
IconURI = 'https://github.com/StartAutomating/Irregular/blob/master/Assets/Irregular_600_Square.png'
1616
}
1717
ReleaseNotes = @'
18+
0.6.2
19+
---
20+
New Regular Expressions:
21+
* ?<Unix_Cron_Interval> (Fixes #67)
22+
* ?<Unix_Duration> (Fixes #69)
23+
1824
0.6.1
1925
---
2026
* New Command: Remove-RegEx (Fixes #62)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<img src='Assets/Irregular_Wide.png' />
33
<h2>Regular Expressions made Strangely Simple</h2>
44
<h3>A PowerShell module that helps you understand, use, and build Regular Expressions.</h3>
5-
<a href='https://dev.azure.com/StartAutomating/Irregular/_build/latest?definitionId=1&branchName=master'>
6-
<img src='https://dev.azure.com/StartAutomating/Irregular/_apis/build/status/StartAutomating.Irregular?branchName=master' />
5+
<a href='https://github.com/StartAutomating/Irregular/actions/workflows/IrregularTests.yml'>
6+
<img src='https://github.com/StartAutomating/Irregular/actions/workflows/IrregularTests.yml/badge.svg' />
77
</a>
88
</div>
99

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
2+
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path
3+
4+
Write-RegEx -Description "Matches a Cron interval" |
5+
Write-RegEx -Pattern @'
6+
(?>
7+
(?<Any>\*) # An asterisk
8+
| # or
9+
(?<Start>
10+
(?>[0-5][0-9]|[0-4]\d|\d{1,1}) # A number between 0 and 59
11+
)
12+
(?<End>
13+
\- # a dash
14+
(?>[0-5][0-9]|[0-4]\d|\d{1,1}) # followed by another number between 0 and 59
15+
){0,1}
16+
(?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
17+
)
18+
'@ -Name Minute -Min 1 |
19+
Write-RegEx -CharacterClass Whitespace -Comment "# A space" |
20+
Write-RegEx -Pattern @'
21+
(?>
22+
(?<Any>\*) # An asterisk
23+
| # or
24+
(?<Start>
25+
(?>[0-2][0-3]|[0-1]\d|\d{1,1}) # A number between 0 and 23
26+
)
27+
(?<End>
28+
\- # a dash
29+
(?>[0-2][0-3]|[0-1]\d|\d{1,1}) # followed by another number between 0 and 23
30+
){0,1}
31+
(?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
32+
)
33+
'@ -Name Hour -Min 1 |
34+
Write-RegEx -CharacterClass Whitespace -Comment "# A space" |
35+
Write-RegEx -Pattern @'
36+
(?>
37+
(?<Any>\*) # An asterisk
38+
| # or
39+
(?<Start>
40+
(?>3[0-1]|[0-2][1-9]|[1-9]) # A number between 1 and 31
41+
)
42+
(?<End>
43+
\- # a dash
44+
(?>3[0-1]|[0-2][1-9]|[1-9]) # followed by another number between 1 and 31
45+
){0,1}
46+
(?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
47+
)
48+
'@ -Name Day -Min 1 |
49+
Write-RegEx -CharacterClass Whitespace -Comment "# A space" |
50+
Write-RegEx -Pattern @'
51+
(?>
52+
(?<Any>\*) # An asterisk
53+
| # or
54+
(?<Start>
55+
(?>1[0-2]|[1-9]) # A number between 1 and 12
56+
)
57+
(?<End>
58+
\- # a dash
59+
(?>1[0-2]|[1-9]) # followed by another number between 1 and 12
60+
){0,1}
61+
(?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
62+
)
63+
'@ -Name Month -Min 1 |
64+
Write-RegEx -CharacterClass Whitespace -Comment "# A space" |
65+
Write-RegEx -Pattern @'
66+
(?>
67+
(?<Any>\*) # An asterisk
68+
| # or
69+
(?<Start>
70+
(?>[0-6]) # A number between 0 and 6
71+
)
72+
(?<End>
73+
\- # a dash
74+
(?>[0-6]) # followed by another number between 0 and 6
75+
){0,1}
76+
(?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
77+
)
78+
'@ -Name DayOfWeek -Min 1 |
79+
Set-Content -Path (Join-Path $myRoot $myName) -PassThru
80+
81+
82+
83+

RegEx/Unix/Cron_Interval.regex.txt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Matches a Cron interval
2+
(?<Minute>(?>
3+
(?<Any>\*) # An asterisk
4+
| # or
5+
(?<Start>
6+
(?>[0-5][0-9]|[0-4]\d|\d{1,1}) # A number between 0 and 59
7+
)
8+
(?<End>
9+
\- # a dash
10+
(?>[0-5][0-9]|[0-4]\d|\d{1,1}) # followed by another number between 0 and 59
11+
){0,1}
12+
(?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
13+
)){1,}\s # A space
14+
(?<Hour>(?>
15+
(?<Any>\*) # An asterisk
16+
| # or
17+
(?<Start>
18+
(?>[0-2][0-3]|[0-1]\d|\d{1,1}) # A number between 0 and 23
19+
)
20+
(?<End>
21+
\- # a dash
22+
(?>[0-2][0-3]|[0-1]\d|\d{1,1}) # followed by another number between 0 and 23
23+
){0,1}
24+
(?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
25+
)){1,}\s # A space
26+
(?<Day>(?>
27+
(?<Any>\*) # An asterisk
28+
| # or
29+
(?<Start>
30+
(?>3[0-1]|[0-2][1-9]|[1-9]) # A number between 1 and 31
31+
)
32+
(?<End>
33+
\- # a dash
34+
(?>3[0-1]|[0-2][1-9]|[1-9]) # followed by another number between 1 and 31
35+
){0,1}
36+
(?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
37+
)){1,}\s # A space
38+
(?<Month>(?>
39+
(?<Any>\*) # An asterisk
40+
| # or
41+
(?<Start>
42+
(?>1[0-2]|[1-9]) # A number between 1 and 12
43+
)
44+
(?<End>
45+
\- # a dash
46+
(?>1[0-2]|[1-9]) # followed by another number between 1 and 12
47+
){0,1}
48+
(?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
49+
)){1,}\s # A space
50+
(?<DayOfWeek>(?>
51+
(?<Any>\*) # An asterisk
52+
| # or
53+
(?<Start>
54+
(?>[0-6]) # A number between 0 and 6
55+
)
56+
(?<End>
57+
\- # a dash
58+
(?>[0-6]) # followed by another number between 0 and 6
59+
){0,1}
60+
(?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
61+
)){1,}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
2+
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path
3+
4+
Write-RegEx -Description "Matches a Duration, defined in ISO 8601" |
5+
Write-RegEx -LiteralCharacter 'P' -Comment "A literal P denotes the period" |
6+
Write-RegEx -Atomic -Pattern (
7+
Write-RegEx -CharacterClass Digit -Repeat -Name Year |
8+
Write-RegEx -LiteralCharacter 'Y' -Comment "An optional year can be denoted with \d+Y"
9+
) -Optional |
10+
Write-RegEx -Atomic -Pattern (
11+
Write-RegEx -CharacterClass Digit -Repeat -Name Month |
12+
Write-RegEx -LiteralCharacter 'M' -Comment "An optional month can be denoted with \d+M"
13+
) -Optional |
14+
Write-RegEx -Atomic -Pattern (
15+
Write-RegEx -CharacterClass Digit -Repeat -Name Week |
16+
Write-RegEx -LiteralCharacter 'W' -Comment "An optional week can be denoted with \d+W"
17+
) -Optional |
18+
Write-RegEx -Atomic -Pattern (
19+
Write-RegEx -CharacterClass Digit -Repeat -Name Day |
20+
Write-RegEx -LiteralCharacter 'D' -Comment "An optional day can be denoted with \d+D"
21+
) -Optional |
22+
Write-RegEx -LiteralCharacter 'T' -Comment "A literal T starts the time component" -Optional |
23+
Write-RegEx -Atomic -Pattern (
24+
Write-RegEx -CharacterClass Digit -Repeat -Name Hour |
25+
Write-RegEx -LiteralCharacter 'H' -Comment "An optional hour can be denoted with \d+H"
26+
) -Optional |
27+
Write-RegEx -Atomic -Pattern (
28+
Write-RegEx -CharacterClass Digit -Repeat -Name Minute |
29+
Write-RegEx -LiteralCharacter 'M' -Comment "An optional minute can be denoted with \d+M"
30+
) -Optional |
31+
Write-RegEx -Atomic -Pattern (
32+
Write-RegEx -CharacterClass Digit -Repeat -Name Second |
33+
Write-RegEx -LiteralCharacter 'S' -Comment "An optional second can be denoted with \d+S"
34+
) -Optional |
35+
Set-Content -Path (Join-Path $myRoot $myName)
36+
37+
38+
39+
40+

RegEx/Unix/Duration.regex.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Matches a Duration, defined in ISO 8601
2+
P # A literal P denotes the period
3+
(?>
4+
(?<Year>\d+)Y # An optional year can be denoted with \d+Y
5+
)?(?>
6+
(?<Month>\d+)M # An optional month can be denoted with \d+M
7+
)?(?>
8+
(?<Week>\d+)W # An optional week can be denoted with \d+W
9+
)?(?>
10+
(?<Day>\d+)D # An optional day can be denoted with \d+D
11+
)?T? # A literal T starts the time component
12+
(?>
13+
(?<Hour>\d+)H # An optional hour can be denoted with \d+H
14+
)?(?>
15+
(?<Minute>\d+)M # An optional minute can be denoted with \d+M
16+
)?(?>
17+
(?<Second>\d+)S # An optional second can be denoted with \d+S
18+
)?

0 commit comments

Comments
 (0)