Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
7c688c2
?<PowerShell_Requires>: Allowing open ended requirement (Fixes #182)
Feb 11, 2023
d75bcd5
?<PowerShell_Requires>: Allowing open ended requirement (Fixes #182)
Feb 11, 2023
4fb32e2
?<PowerShell_Requires>: Allowing open ended requirement (Fixes #182)
Feb 11, 2023
ee8a974
?<PowerShell_Requires>: Allowing open ended requirement (Fixes #182)
Feb 11, 2023
3d4291c
?<PowerShell_Requires>: Allowing open ended requirement (Fixes #182)
Feb 11, 2023
0eac876
?<PowerShell_Requires>: Renaming capture (re #182)
Feb 11, 2023
5d77cb0
?<PowerShell_Requires>: Renaming capture (re #182)
Feb 11, 2023
5a0e676
?<PowerShell_Requires>: Renaming capture (re #182)
Feb 11, 2023
0372782
?<PowerShell_Requires>: Renaming capture (re #182)
Feb 11, 2023
bf60202
?<PowerShell_Requires>: Renaming capture (re #182)
Feb 11, 2023
f29b932
Adding PowerShell regex tests (re #182)
Feb 11, 2023
88e05b9
Adding PowerShell regex tests (re #182)
Feb 11, 2023
4be6209
Adding PowerShell regex tests (re #182)
Feb 11, 2023
924d35d
Adding PowerShell regex tests (re #182)
Feb 11, 2023
ced091f
Adding PowerShell regex tests (re #182)
Feb 11, 2023
a43ffcd
Adding PowerShell regex tests (re #182)
Feb 11, 2023
d1d056c
Adding Compres-Regex (Fixes #178)
Jul 11, 2023
165507c
Adding Compres-Regex (Fixes #178)
Jul 11, 2023
d927b40
Adding Compres-Regex (Fixes #178)
Jul 11, 2023
7b656ca
Adding Compres-Regex (Fixes #178)
Jul 11, 2023
d41a6ce
Adding ?<Degrees> (Fixes #185)
Jul 11, 2023
2588570
Adding ?<Degrees> (Fixes #185)
Jul 11, 2023
52996ed
Adding ?<Degrees> (Fixes #185)
Jul 11, 2023
6399cd1
Merge pull request #190 from StartAutomating/Irregular-PowerShell-Req…
StartAutomating Jul 11, 2023
4fe32ea
Adding ?<YAML_Key> (Fixes #191)
Jul 11, 2023
38cf81f
Updating SavedPatterns.md [skip ci]
Jul 11, 2023
3d21a16
Adding ?<YAML_Key> (Fixes #191)
Jul 11, 2023
26dab49
Adding ?<YAML_Key> (Fixes #191)
Jul 11, 2023
5c631bb
Adding ?<YAML_Key> (Fixes #191)
Jul 11, 2023
20e1725
Adding ?<YAML_Value> (Fixes #192)
Jul 11, 2023
66fed58
Updating SavedPatterns.md [skip ci]
Jul 11, 2023
8bf31f1
Adding ?<YAML_Value> (Fixes #192)
Jul 11, 2023
93f9fb6
Adding ?<YAML_Value> (Fixes #192)
Jul 11, 2023
fd58ee6
Adding ?<YAML_Value> (Fixes #192)
Jul 11, 2023
29fc36e
Adding ?<YAML_Value> (Fixes #192)
Jul 11, 2023
dee27b1
Adding ?<YAML_Value> (Fixes #192)
Jul 11, 2023
19d4769
Adding ?<Git_Commit> (Fixes #193)
Jul 11, 2023
bb82d1b
Updating SavedPatterns.md [skip ci]
Jul 11, 2023
c778010
Adding ?<Git_Commit> (Fixes #193)
Jul 11, 2023
0e941ed
Adding ?<Git_Commit> (Fixes #193)
Jul 11, 2023
d2a8b9e
Adding ?<Git_Commit> (Fixes #193)
Jul 11, 2023
56b198e
Adding ?<Git_Commit> (Fixes #193)
Jul 11, 2023
77fca8c
Renaming ANSI Regexes to Console (Fixes #188)
Jul 11, 2023
f0abd3d
Renaming ANSI Regexes to Console (Fixes #188)
Jul 11, 2023
a215d93
Renaming ANSI Regexes to Console (Fixes #188)
Jul 11, 2023
168b5dc
Updating SavedPatterns.md [skip ci]
Jul 11, 2023
4a79f8e
Renaming ANSI Regexes to Console (Fixes #188)
Jul 11, 2023
2d51261
Renaming ANSI Regexes to Console (Fixes #188)
Jul 11, 2023
8f858f2
Renaming ANSI Regexes to Console (Fixes #188)
Jul 11, 2023
f3935ab
Renaming ANSI Regexes to Console (Fixes #188)
Jul 11, 2023
ae54718
Renaming ANSI Regexes to Console (Fixes #188)
Jul 11, 2023
2618914
Renaming ANSI Regexes to Console (Fixes #188)
Jul 11, 2023
bd17b68
Renaming ANSI Regexes to Console (Fixes #188)
Jul 11, 2023
b332403
Renaming ANSI Regexes to Console (Fixes #188)
Jul 11, 2023
ade8750
Updating Console Tests (Fixes #188)
Jul 16, 2023
bf0ba9c
Updating Console Tests (Fixes #188)
Jul 16, 2023
4c1b47f
Adding ?<PowerShell_Hashtable> ( Fixes #194 )
Jul 16, 2023
a28f32a
Updating SavedPatterns.md [skip ci]
Jul 16, 2023
763aa09
Adding ?<PowerShell_Hashtable> ( Fixes #194 )
Jul 16, 2023
80d7fda
Adding ?<PowerShell_Hashtable> ( Fixes #194 )
Jul 16, 2023
c8e7bf2
Adding ?<PowerShell_Hashtable> ( Fixes #194 )
Jul 16, 2023
ef7e2f8
Adding ?<PowerShell_Hashtable> ( Fixes #194 )
Jul 16, 2023
f1f4712
Adding ?<RegularExpression_GroupName> (Fixes #195)
Jul 16, 2023
4813695
Updating SavedPatterns.md [skip ci]
Jul 16, 2023
a1cf344
Adding ?<RegularExpression_GroupName> (Fixes #195)
Jul 16, 2023
7324ba4
Adding ?<RegularExpression_GroupName> (Fixes #195)
Jul 16, 2023
e7d0d54
Adding ?<RegularExpression_GroupName> (Fixes #195)
Jul 16, 2023
dcd7661
Adding ?<RegularExpression_GroupName> (Fixes #195)
Jul 16, 2023
4a9ccfa
Updating Module Version [0.7.8] and CHANGELOG
Jul 20, 2023
eb3f782
Updating Module Version [0.7.8] and CHANGELOG
Jul 20, 2023
a01c002
Updating Module Version [0.7.8] and CHANGELOG
Jul 20, 2023
9061362
Updating Module Version [0.7.8] and CHANGELOG
Jul 20, 2023
ee26970
Updating Module Version [0.7.8] and CHANGELOG
Jul 20, 2023
f979564
Updating Module Version [0.7.8] and CHANGELOG
Jul 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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.
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.
Loading