Skip to content

Commit

Permalink
Merge pull request #196 from StartAutomating/Irregular-Updates
Browse files Browse the repository at this point in the history
Irregular 0.7.8
  • Loading branch information
StartAutomating authored Jul 20, 2023
2 parents 99e11b1 + f979564 commit 3e1443d
Show file tree
Hide file tree
Showing 73 changed files with 696 additions and 177 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
## 0.7.7:
## 0.7.8:

* Adding Compress-Regex (Fixes #178)
* New Regexes:
* ?<YAML_Value> (Fixes #192)
* ?<YAML_Key> (Fixes #191)
* ?<Degrees> (Fixes #185)
* ?<Git_Commit> (Fixes #193)
* ?<RegularExpression_GroupName> ( #195 )
* ?<PowerShell_Hashtable> ( Fixes #194 )
* ?<PowerShell_Requires>: Allowing open ended requirement (Fixes #182)
Renaming ANSI Regexes to Console (Fixes #188)

---

## 0.7.7:

New Patterns:

Expand Down
60 changes: 60 additions & 0 deletions Compress-RegEx.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function Compress-Regex
{
<#
.SYNOPSIS
Compresses Regular Expressions
.DESCRIPTION
Compresses a Regular Expression, removing all whitespace and comments.
This will make a regular expression much more difficult to read, and a bit shorter.
.EXAMPLE
New-Regex -Description "This is a description of a regex nobody will care about" |
New-Regex -Name Width @(
?<Decimals>
) |
New-Regex -Name Height @(
?<Decimals>
) | Compress-Regex
#>
param(
# The regular expression to compress.
[Parameter(Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName,
Position=0)]
[Alias('RegularExpression','Pattern','Expression')]
[Regex]
$Regex,

# The Match Timeout.
# By default, this value will be carried over from the -RegEx.
[timespan]
$MatchTimeout = '00:00:01'
)

process {
# Create a new regex from the old:
[Regex]::new(
(
# To compress the regex, split it by newlines
"$Regex" -split '(?>\r\n|\n)' -replace
# and strip comments
'(?<!\\)#.+$' -join ([Environment]::NewLine) -replace
# and strip whitespace.
'[\s\n\r]'
),
# We'll keep the regex options should remain the same, for now.
$Regex.Options,
$(
# If we provided a -MatchTimeout
if ($PSBoundParameters["MatchTimeout"]) {
$MatchTimeout # use that
} elseif ($Regex.MatchTimeout.TotalSeconds -gt 0) {
$Regex.MatchTimeout # otherwise, carry the timeout from the [Regex]
} else {
$MatchTimeout # and if it didn't have one, use the default for -MatchTimeout.
}
)
)
}
}
2 changes: 1 addition & 1 deletion Irregular.format.ps1xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-16"?>
<!-- Generated with EZOut 1.9.9: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<!-- Generated with EZOut 2.0: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Configuration>
<ViewDefinitions>
<View>
Expand Down
32 changes: 30 additions & 2 deletions Irregular.psd1
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
@{
ModuleVersion = '0.7.7'
ModuleVersion = '0.7.8'
RootModule = 'Irregular.psm1'
Description = 'Regular Expressions made Strangely Simple'
FormatsToProcess = 'Irregular.format.ps1xml'
TypesToProcess = 'Irregular.types.ps1xml'
Guid = '39eb966d-7437-4e2c-abae-a496e933fb23'
Author = 'James Brundage'
Copyright = '2019-2022 Start-Automating'
Copyright = '2019-2023 Start-Automating'
PrivateData = @{
PSData = @{
Tags = 'RegularExpressions', 'RegEx', 'Irregular', 'PatternMatching', 'PipeScript'
ProjectURI = 'https://github.com/StartAutomating/Irregular'
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.8:
* Adding Compress-Regex (Fixes #178)
* New Regexes:
* ?<YAML_Value> (Fixes #192)
* ?<YAML_Key> (Fixes #191)
* ?<Degrees> (Fixes #185)
* ?<Git_Commit> (Fixes #193)
* ?<RegularExpression_GroupName> ( #195 )
* ?<PowerShell_Hashtable> ( Fixes #194 )
* ?<PowerShell_Requires>: Allowing open ended requirement (Fixes #182)
Renaming ANSI Regexes to Console (Fixes #188)
---
## 0.7.7:
New Patterns:
Expand Down Expand Up @@ -211,6 +226,19 @@ Hat Tips: @JayKul, @LaurentDardenne
Additional Changes in [ChangeLog](CHANGELOG.md)
'@
}
ScriptTypes = @{
RegExGenerator = @{
Pattern = '\.regex\.ps1$'
}
RegExSource = @{
Pattern = '\.regex\.source\.ps1$'
}
}
ApplicationTypes = @{
RegExFile = @{
Pattern ='\.regex\.txt'
}
}
}
}

1 change: 1 addition & 0 deletions Irregular.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
. $psScriptRoot\Get-RegEx.ps1
. $psScriptRoot\Compress-RegEx.ps1
. $psScriptRoot\Export-RegEx.ps1
. $psScriptRoot\Import-RegEx.ps1
. $psScriptRoot\New-RegEx.ps1
Expand Down
2 changes: 1 addition & 1 deletion Irregular.types.ps1xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-16"?>
<!-- Generated with EZOut 1.9.9: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<!-- Generated with EZOut 2.0: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
<Types>
<Type>
<Name>Irregular.Match.Extract</Name>
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.7.7'>v 0.7.7 </a>
<a href='https://github.com/StartAutomating/Irregular/releases/tag/v0.7.8'>v 0.7.8 </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 138 useful [named expressions](SavedPatterns.md), and lets you create more.
Irregular comes with 144 useful [named expressions](SavedPatterns.md), and lets you create more.

To see the expressions that ship with Irregular, run:

Expand Down
27 changes: 0 additions & 27 deletions RegEx/ANSI/ANSI.tests.ps1

This file was deleted.

28 changes: 0 additions & 28 deletions RegEx/ANSI/README.md

This file was deleted.

20 changes: 0 additions & 20 deletions RegEx/ANSI/Style.regex.source.ps1

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ $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>'
New-RegEx -Pattern '?<Console_24BitColor>'
New-RegEx -Pattern '?<Console_8BitColor>'
New-RegEx -Pattern '?<Console_4BitColor>'
New-RegEx -Pattern '?<Console_DefaultColor>'
) |
Set-Content -Path (Join-Path $myRoot $myName) -PassThru
24 changes: 16 additions & 8 deletions RegEx/ANSI/Color.regex.txt → RegEx/Console/Color.regex.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Matches an ANSI color
(?>
(?<ANSI_24BitColor>
(?<Console_24BitColor>
(?-i)\e # An Escape
\[ # Followed by a bracket
(?>
Expand All @@ -12,7 +12,7 @@
m)
)
|
(?<ANSI_8BitColor>
(?<Console_8BitColor>
(?-i)\e # An Escape
\[ # Followed by a bracket
(?>
Expand All @@ -29,17 +29,25 @@ m |
m))
)
|
(?<ANSI_4BitColor>
(?<Console_4BitColor>
\e # An Escape
\[ # Followed by a bracket
(?<Color>(?>
(?<IsBright>1)?\;{0,1}(?<IsForegroundColor>3) |
(?<IsBright>(?<IsForegroundColor>9)) |
(?<IsBright>1)?\;{0,1}(?<IsBackgroundColor>4) |
(?<IsBright>(?<IsBackgroundColor>10)))(?<ColorNumber>[0-7])m)
(?<IsBright>1)?\;{0,1} # A 1 and a semicolon indicate a bright color
(?<IsForegroundColor>3) # A number that starts with 3 indicates foreground color
|
(?<IsBright>(?<IsForegroundColor>9)) # OR it could be a less common bright foreground color, which starts with 9
|
(?<IsBright>1)?\;{0,1} # A 1 and a semicolon indicate a bright color
(?<IsBackgroundColor>4) # A number that starts with 3 indicates foreground color
|
(?<IsBright>(?<IsBackgroundColor>10)) # OR it could be a less common bright foreground color, which starts with 9
)(?<ColorNumber>[0-7]) # The color number will be between 0 and 7
(?:\;{0,1}(?<IsBright>1)?)? # Brightness can also come after a color
m)
)
|
(?<ANSI_DefaultColor>
(?<Console_DefaultColor>
(?-i)\e # An Escape
\[ # Followed by a bracket
(?<Color>(?>
Expand Down
27 changes: 27 additions & 0 deletions RegEx/Console/Console.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe 'Irregular Console Patterns' {
it 'Can match any Escape sequence' {
"$([char]0x1b)[0m" | ?<Console_Code> | Select-Object -ExpandProperty Length | Should -be 4

"$([char]0x1b)[1;3;5,~" | ?<Console_Code> | Select-Object -ExpandProperty Length | Should -be 9
}
context 'Console Colors' {
it 'Can Match a 4-bit color' {
$x = "$([char]0x1b)[32m" | ?<Console_4BitColor> -Extract
$x.ColorNumber | Should -Be 2
$x.IsForegroundColor | Should -Be 3
}

it 'Can Match a 24-bit color' {
$x = "$([char]0x1b)[38;2;255;100;0m" | ?<Console_24BitColor> -Extract
$x.Red | Should -be 255
$x.Green | Should -be 100
$x.Blue | Should -be 0
}
}

context 'Console Styles' {
it 'Can Match Console Styles' {
@("$([char]0x1b)[3m Italics $([char]0x1b)[23m" | ?<Console_Style>).Count | Should -be 2
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions RegEx/Console/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
This directory contains regular expressions for advanced console features, such as [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 |Source |
|---------------------------------------------------|-------------------------------------------------------------|----------------------------------------|
|[?<Console_24BitColor>](24BitColor.regex.txt) |Matches an ANSI 24-bit color |[source](24BitColor.regex.source.ps1) |
|[?<Console_4BitColor>](4BitColor.regex.txt) |Matches an ANSI 3 or 4-bit color |[source](4BitColor.regex.source.ps1) |
|[?<Console_8BitColor>](8BitColor.regex.txt) |Matches an ANSI 8-bit color |[source](8BitColor.regex.source.ps1) |
|[?<Console_Blink>](Blink.regex.txt) |Matches ANSI Blink Start or End |[source](Blink.regex.source.ps1) |
|[?<Console_Bold>](Bold.regex.txt) |Matches an ANSI Bold (aka bright) Start or End |[source](Bold.regex.source.ps1) |
|[?<Console_Code>](Code.regex.txt) |Matches an ANSI escape code |[source](Code.regex.source.ps1) |
|[?<Console_Color>](Color.regex.txt) |Matches an ANSI color |[source](Color.regex.source.ps1) |
|[?<Console_Cursor>](Cursor.regex.txt) |Matches an ANSI cursor control |[source](Cursor.regex.source.ps1) |
|[?<Console_DefaultColor>](DefaultColor.regex.txt) |Matches an ANSI default color |[source](DefaultColor.regex.source.ps1) |
|[?<Console_Faint>](Faint.regex.txt) |Matches an ANSI Faint (aka dim) Start or End |[source](Faint.regex.source.ps1) |
|[?<Console_Hide>](Hide.regex.txt) |Matches ANSI Hide (aka conceal) Start or End |[source](Hide.regex.source.ps1) |
|[?<Console_Invert>](Invert.regex.txt) |Matches ANSI Invert Start or End |[source](Invert.regex.source.ps1) |
|[?<Console_Italic>](Italic.regex.txt) |Matches ANSI Italic Start or End |[source](Italic.regex.source.ps1) |
|[?<Console_Link>](Link.regex.txt) |Matches ANSI Hyperlink |[source](Link.regex.source.ps1) |
|[?<Console_Note>](Note.regex.txt) |Matches an ANSI VT520 Note |[source](Note.regex.source.ps1) |
|[?<Console_Reset>](Reset.regex.txt) |Matches an ANSI Reset (this clears formatting) |[source](Reset.regex.source.ps1) |
|[?<Console_Strikethrough>](Strikethrough.regex.txt)|Matches ANSI Strikethrough (aka crossed out) Start or End |[source](Strikethrough.regex.source.ps1)|
|[?<Console_Style>](Style.regex.txt) |Matches an ANSI style (color or text option) |[source](Style.regex.source.ps1) |
|[?<Console_Underline>](Underline.regex.txt) |Matches ANSI Underline/DoubleUnderline Start or Underline End|[source](Underline.regex.source.ps1) |


2 changes: 1 addition & 1 deletion RegEx/ANSI/README.ps1.md → RegEx/Console/README.ps1.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This directory contains regular expressions for [ANSI escape sequences](https://en.wikipedia.org/wiki/ANSI_escape_code).
This directory contains regular expressions for advanced console features, such as [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)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 3e1443d

Please sign in to comment.