Skip to content

Commit

Permalink
Merge pull request #125 from StartAutomating/IrregularUpdates
Browse files Browse the repository at this point in the history
Irregular updates
  • Loading branch information
StartAutomating authored Sep 12, 2022
2 parents 986b233 + a1811cc commit f061403
Show file tree
Hide file tree
Showing 34 changed files with 1,384 additions and 308 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/IrregularTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ jobs:
$ModulePath,
[string[]]
$Exclude = @('*.png', '*.mp4', '*.jpg','*.jpeg')
$Exclude = @('*.png', '*.mp4', '*.jpg','*.jpeg', '*.gif')
)
$gitHubEvent = if ($env:GITHUB_EVENT_PATH) {
[IO.File]::ReadAllText($env:GITHUB_EVENT_PATH) | ConvertFrom-Json
} else { $null }
if (-not $Exclude) {
$Exclude = @('*.png', '*.mp4', '*.jpg','*.jpeg')
$Exclude = @('*.png', '*.mp4', '*.jpg','*.jpeg', '*.gif')
}
Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
## 0.6.9:
## 0.7.0:
* New Patterns:
* ANSI
* ?<ANSI_Code> (Fixes #123)
* ?<ANSI_Color> (Fixes #124)
* ?<ANSI_DefaultColor>
* ?<ANSI_4BitColor>
* ?<ANSI_8BitColor>
* ?<ANSI_24BitColor>
* Mustache
* ?<Mustache_Tag> (Fixes #121)
* New-Regex -LiteralCharacter '_' no longer escapes (Fixes #122)
* Reducing module size (excluding assets) (Fixes #118)
---

## 0.6.9:
* Adding ?<Markdown_Link> (Fixes #117)
* GitHub Action now prefers local bits (Fixes #111)
* Using PipeScript to enhance the repository experience (Fixes #119)
Expand Down
17 changes: 16 additions & 1 deletion Irregular.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.6.9'
ModuleVersion = '0.7.0'
RootModule = 'Irregular.psm1'
Description = 'Regular Expressions made Strangely Simple'
FormatsToProcess = 'Irregular.format.ps1xml'
Expand All @@ -14,6 +14,21 @@
LicenseURI = 'https://github.com/StartAutomating/Irregular/blob/master/LICENSE'
IconURI = 'https://github.com/StartAutomating/Irregular/blob/master/Assets/Irregular_600_Square.png'
ReleaseNotes = @'
## 0.7.0:
* New Patterns:
* ANSI
* ?<ANSI_Code> (Fixes #123)
* ?<ANSI_Color> (Fixes #124)
* ?<ANSI_DefaultColor>
* ?<ANSI_4BitColor>
* ?<ANSI_8BitColor>
* ?<ANSI_24BitColor>
* Mustache
* ?<Mustache_Tag> (Fixes #121)
* New-Regex -LiteralCharacter '_' no longer escapes (Fixes #122)
* Reducing module size (excluding assets) (Fixes #118)
---
## 0.6.9:
* Adding ?<Markdown_Link> (Fixes #117)
* GitHub Action now prefers local bits (Fixes #111)
Expand Down
2 changes: 1 addition & 1 deletion New-RegEx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@
$ccLookup[$notcc]
})

$lc = @($literalCharacter -replace '[\p{P}\p{S}]', '\$0')
$lc = @($literalCharacter -replace '[\p{P}\p{S}-[_]]', '\$0')
$notLC = @($ExcludeliteralCharacter -replace '[\p{P}\p{S}]', '\$0')

$charSet = @(
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h2>Regular Expressions made Strangely Simple</h2>
<h3>A PowerShell module that helps you understand, use, and build Regular Expressions.</h3>
<h4>
<a href='https://github.com/StartAutomating/Irregular/releases/tag/v0.6.9'>v 0.6.9 </a>
<a href='https://github.com/StartAutomating/Irregular/releases/tag/v0.7.0'>v 0.7.0 </a>
</h4>
<a href='https://www.powershellgallery.com/packages/Irregular/'>
<img src='https://img.shields.io/powershellgallery/dt/Irregular' />
Expand Down Expand Up @@ -32,7 +32,7 @@ Once you understand some basics of that syntax, regular expressions become a lot
3. A Regex can have comments! ( # Like this in .NET ( or like (?#this comment) in ECMAScript ) ).
4. You don't have to do it all in one expression!

Irregular comes with 111 useful [named expressions](SavedPatterns.md), and lets you create more.
Irregular comes with 118 useful [named expressions](SavedPatterns.md), and lets you create more.

To see the expressions that ship with Irregular, run:

Expand Down
16 changes: 16 additions & 0 deletions RegEx/ANSI/24BitColor.regex.source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path

New-RegEx -Description "Matches an ANSI 24-bit color" -Modifier IgnoreCase -Not |
New-RegEx -CharacterClass Escape -Comment 'An Escape' |
New-RegEx -LiteralCharacter '[' -Comment 'Followed by a bracket' |
New-RegEx -Pattern '38;2;' |
New-RegEx -Name Color -Pattern (
New-Regex -Name Red -Pattern '(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})' -Comment 'Red is the first 0-255 value' |
New-RegEx -Pattern ';' |
New-Regex -Name Red -Pattern '(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})' -Comment 'Green is the second 0-255 value' |
New-RegEx -Pattern ';' |
New-Regex -Name Blue -Pattern '(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})' -Comment 'Blue is the third 0-255 value' |
New-RegEx -Pattern 'm'
) |
Set-Content -Path (Join-Path $myRoot $myName)
7 changes: 7 additions & 0 deletions RegEx/ANSI/24BitColor.regex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Matches an ANSI 24-bit color
(?-i)\e # An Escape
\[ # Followed by a bracket
38;2;(?<Color>(?<Red>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Red is the first 0-255 value
;(?<Red>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Green is the second 0-255 value
;(?<Blue>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Blue is the third 0-255 value
m)
16 changes: 16 additions & 0 deletions RegEx/ANSI/4BitColor.regex.source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path

New-RegEx -Description "Matches an ANSI 3 or 4-bit color" |
New-RegEx -CharacterClass Escape -Comment 'An Escape' |
New-RegEx -LiteralCharacter '[' -Comment 'Followed by a bracket' |
New-RegEx -Pattern (
New-RegEx -Pattern 1 -Optional -Name IsBright |
New-RegEx -LiteralCharacter ';' -Optional |
New-RegEx -Pattern '3[0-7]' -Name ForegroundColor -Optional |
New-RegEx -If ForegroundColor -Then 'm' -Else (
New-RegEx -Pattern '4[0-7]' -Name BackgroundColor |
New-RegEx -Pattern 'm' -Modifier IgnoreCase -Not
)
) -Name Color |
Set-Content -Path (Join-Path $myRoot $myName)
4 changes: 4 additions & 0 deletions RegEx/ANSI/4BitColor.regex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Matches an ANSI 3 or 4-bit color
\e # An Escape
\[ # Followed by a bracket
(?<Color>(?<IsBright>1)?\;?(?<ForegroundColor>3[0-7])?(?(ForegroundColor)(m)|((?<BackgroundColor>4[0-7])m)))
20 changes: 20 additions & 0 deletions RegEx/ANSI/8BitColor.regex.source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path

New-RegEx -Description "Matches an ANSI 8-bit color" -Modifier IgnoreCase -Not |
New-RegEx -CharacterClass Escape -Comment 'An Escape' |
New-RegEx -LiteralCharacter '[' -Comment 'Followed by a bracket' |
New-RegEx -Pattern '38;5;' |
New-RegEx -Name Color -Pattern (
New-RegEx -Atomic -Or @(
New-Regex -Name StandardColor -Pattern '[0-7]' -Comment '0 -7 are standard colors' |
New-RegEx -Pattern m
New-Regex -Name BrightColor -Pattern '(?>[8-9]|1[0-5])' -Comment '8-15 are bright colors' |
New-RegEx -Pattern m
New-Regex -Name CubeColor -Pattern '(?>[0-2][0-3][0-1]|[0-1]\d\d|\d{1,2})' -Comment '16-231 are cubed colors' |
New-RegEx -Pattern m
New-Regex -Name GrayscaleColor -Pattern '(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})' -Comment '232-255 are grayscales' |
New-RegEx -Pattern m
)
) |
Set-Content -Path (Join-Path $myRoot $myName)
12 changes: 12 additions & 0 deletions RegEx/ANSI/8BitColor.regex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Matches an ANSI 8 bit color
(?-i)\e # An Escape
\[ # Followed by a bracket
38;5;(?<Color>(?>
(?<StandardColor>[0-7]) # 0 -7 are standard colors
m |
(?<BrightColor>(?>[8-9]|1[0-5])) # 8-15 are bright colors
m |
(?<CubeColor>(?>[0-2][0-3][0-1]|[0-1]\d\d|\d{1,2})) # 16-231 are cubed colors
m |
(?<GrayscaleColor>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # 232-255 are grayscales
m))
16 changes: 16 additions & 0 deletions RegEx/ANSI/Code.regex.source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path

New-RegEx -Description "Matches an ANSI escape code" -Modifier IgnoreCase -Not |
New-RegEx -CharacterClass Escape -Comment 'An Escape' |
New-RegEx -LiteralCharacter '[' -Comment 'Followed by a bracket' |
New-RegEx -Name ParameterBytes (
New-Regex -CharacterClass Digit -LiteralCharacter ':;<=>?' -Min 0
) -Comment "Followed by zero or more parameter bytes" |
New-RegEx -Name IntermediateBytes (
New-Regex -LiteralCharacter (0x21..0x2F -as [char[]]) -Min 0 -CharacterClass Whitespace
) -Comment "Followed by zero or more intermediate bytes" |
New-RegEx -Name FinalByte (
New-RegEx -LiteralCharacter (0x40..0x7E -as [char[]])
) -Comment "Followed by a final byte" |
Set-Content -Path (Join-Path $myRoot $myName)
7 changes: 7 additions & 0 deletions RegEx/ANSI/Code.regex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Matches an ANSI escape code
(?-i)\e # An Escape
\[ # Followed by a bracket
(?<ParameterBytes>[\d\:\;\<\=\>\?]{0,}) # Followed by zero or more parameter bytes
(?<IntermediateBytes>[\s\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/]{0,}) # Followed by zero or more intermediate bytes
(?<FinalByte>[\@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\\\]\^_\`abcdefghijklmnopqrstuvwxyz\{\|\}\~]) # Followed by a final byte

11 changes: 11 additions & 0 deletions RegEx/ANSI/Color.regex.source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path

New-RegEx -Description "Matches an ANSI color" |
New-RegEx -Atomic -Or @(
New-RegEx -Pattern '?<ANSI_24BitColor>'
New-RegEx -Pattern '?<ANSI_8BitColor>'
New-RegEx -Pattern '?<ANSI_4BitColor>'
New-RegEx -Pattern '?<ANSI_DefaultColor>'
) |
Set-Content -Path (Join-Path $myRoot $myName) -PassThru
41 changes: 41 additions & 0 deletions RegEx/ANSI/Color.regex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Matches an ANSI color
(?>
(?<ANSI_24BitColor>
(?-i)\e # An Escape
\[ # Followed by a bracket
38;2;(?<Color>(?<Red>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Red is the first 0-255 value
;(?<Red>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Green is the second 0-255 value
;(?<Blue>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Blue is the third 0-255 value
m)
)
|
(?<ANSI_8BitColor>
(?-i)\e # An Escape
\[ # Followed by a bracket
38;5;(?<Color>(?>
(?<StandardColor>[0-7]) # 0 -7 are standard colors
m |
(?<BrightColor>(?>[8-9]|1[0-5])) # 8-15 are bright colors
m |
(?<CubeColor>(?>[0-2][0-3][0-1]|[0-1]\d\d|\d{1,2})) # 16-231 are cubed colors
m |
(?<GrayscaleColor>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # 232-255 are grayscales
m))
)
|
(?<ANSI_4BitColor>
\e # An Escape
\[ # Followed by a bracket
(?<Color>(?<IsBright>1)?\;?(?<ForegroundColor>3[0-7])?(?(ForegroundColor)(m)|((?<BackgroundColor>4[0-7])m)))
)
|
(?<ANSI_DefaultColor>
(?-i)\e # An Escape
\[ # Followed by a bracket
(?<Color>(?>
(?<DefaultForeground>39) # 39 Represents the default foreground color
m |
(?<DefaultForeground>49) # 49 Represents the default background color
m))
)
)
15 changes: 15 additions & 0 deletions RegEx/ANSI/DefaultColor.regex.source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path

New-RegEx -Description "Matches an ANSI default color" -Modifier IgnoreCase -Not |
New-RegEx -CharacterClass Escape -Comment 'An Escape' |
New-RegEx -LiteralCharacter '[' -Comment 'Followed by a bracket' |
New-RegEx -Name Color -Pattern (
New-RegEx -Atomic -Or @(
New-Regex -Name DefaultForeground -Pattern '39' -Comment '39 Represents the default foreground color' |
New-RegEx -Pattern 'm'
New-Regex -Name DefaultForeground -Pattern '49' -Comment '49 Represents the default background color' |
New-RegEx -Pattern 'm'
)
) |
Set-Content -Path (Join-Path $myRoot $myName)
8 changes: 8 additions & 0 deletions RegEx/ANSI/DefaultColor.regex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Matches an ANSI 24-bit color
(?-i)\e # An Escape
\[ # Followed by a bracket
(?<Color>(?>
(?<DefaultForeground>39) # 39 Represents the default foreground color
m |
(?<DefaultForeground>49) # 49 Represents the default background color
m))
15 changes: 15 additions & 0 deletions RegEx/ANSI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This directory contains regular expressions for [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code).

Note: Using these regular expressions in the terminal may result in awkward output. (the .Match will contain an escape sequence, which will make the next output attempt to use this escape sequence)


|Name |Description |IsGenerator|
|----------------------------------------------|--------------------------------|-----------|
|[?<ANSI_24BitColor>](24BitColor.regex.txt) |Matches an ANSI 24-bit color |False |
|[?<ANSI_4BitColor>](4BitColor.regex.txt) |Matches an ANSI 3 or 4-bit color|False |
|[?<ANSI_8BitColor>](8BitColor.regex.txt) |Matches an ANSI 8 bit color |False |
|[?<ANSI_Code>](Code.regex.txt) |Matches an ANSI escape code |False |
|[?<ANSI_Color>](Color.regex.txt) |Matches an ANSI color |False |
|[?<ANSI_DefaultColor>](DefaultColor.regex.txt)|Matches an ANSI 24-bit color |False |


16 changes: 16 additions & 0 deletions RegEx/ANSI/README.ps1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This directory contains regular expressions for [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code).

Note: Using these regular expressions in the terminal may result in awkward output. (the .Match will contain an escape sequence, which will make the next output attempt to use this escape sequence)

~~~PipeScript{
Import-Module ../../Irregular.psd1 -Global
$directoryName = $pwd | Split-Path -Leaf
[PSCustomObject]@{
Table = Get-Regex -Name "${directoryName}_*" |
Sort-Object Name |
Select @{
Name='Name'
Expression={"[?<$($_.Name)>]($($_.Path | Split-Path -Leaf))"}
}, Description, IsGenerator
}}
~~~
9 changes: 9 additions & 0 deletions RegEx/Mustache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This directory contains regular expressions for [Mustache templates](http://mustache.github.io/).



|Name |Description|IsGenerator|
|--------------------------------|-----------|-----------|
|[?<Mustache_Tag>](Tag.regex.ps1)|True |


15 changes: 15 additions & 0 deletions RegEx/Mustache/README.ps1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This directory contains regular expressions for [Mustache templates](http://mustache.github.io/).


~~~PipeScript{
Import-Module ../../Irregular.psd1 -Global
$directoryName = $pwd | Split-Path -Leaf
[PSCustomObject]@{
Table = Get-Regex -Name "${directoryName}_*" |
Sort-Object Name |
Select @{
Name='Name'
Expression={"[?<$($_.Name)>]($($_.Path | Split-Path -Leaf))"}
}, Description, IsGenerator
}}
~~~
54 changes: 54 additions & 0 deletions RegEx/Mustache/Tag.regex.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
param(
[string]
$Tag,

[ValidateSet('Comment','Escaped','SectionStart','SectionEnd', 'Partial', 'Unescaped')]
[string[]]
$TagType
)

if (-not $tag) {
$tag = @"
(?:.|\s){0,}?(?=\z| # Now we match everything until
(?(IsEscaped)(\}{3})|(\}{2})) # 3 Brackets (if escaped) 2 (if not)
)
"@
}

$mustBeType = $true

$tagTypeRegex = [Ordered]@{
"Escaped" = "\{", "# One more curly bracket marks it as escaped."
"SectionStart" = "\#", "# Starting with a number sign makes it a section start."
"SectionEnd" = "\/", "# Starting with a slash makes it a section end."
"Comment" = "\!", "# Starting with an exclamation point makes it a comment."
"Partial" = "\>", "# Starting with greater than makes it a partial"
"Unescaped" = "\&", "# Unescaped variables start with ampersands."
}

if (-not $TagType) {
$TagType = $TagTypeRegex.Keys
$mustBeType = $false
}
$ValidTagTypes =
@(foreach ($tt in $tagTypeRegex.GetEnumerator()) {
@(
$tt.Value[1]
"(?><Is$($tt.Key)>$($tt.Value[0]))"
) -join [Environment]::NewLine
}) -join ([Environment]::NewLine + '|' + [Environment]::NewLine)

$ValidTagTypes = "(?>
$ValidTagTypes
)$(if (-not $mustBeType) { '?' })"
"
\{{2} # Two curly brackets start a tag
$ValidTagTypes
\s{0,}
(?<Variable>
$tag
)
# Once more, to be sure we're not at the end of the document.
(?(IsEscaped)(\}{3})|(\}{2})) # 3 Brackets (if escaped) 2 (if not)
"
Loading

0 comments on commit f061403

Please sign in to comment.