Skip to content

Commit

Permalink
Merge pull request #152 from StartAutomating/IrregularANSI
Browse files Browse the repository at this point in the history
Irregular ansi
  • Loading branch information
StartAutomating authored Oct 1, 2022
2 parents 6f2cca6 + dacc420 commit 7abe0ff
Show file tree
Hide file tree
Showing 19 changed files with 204 additions and 65 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## 0.7.3:
## 0.7.4:
* ANSI Improvements:
* Regenerated ?<ANSI_Color> (Fixes #150)
* Added ?<ANSI_Cursor> (Fixes #151)
---

## 0.7.3:
* ANSI Improvements:
* Fixed ?<ANSI_Style> (Fixes #143)
* ?<ANSI_4BitColor> now supports bright ranges (Fixes #145)
Expand Down
8 changes: 7 additions & 1 deletion Irregular.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.7.3'
ModuleVersion = '0.7.4'
RootModule = 'Irregular.psm1'
Description = 'Regular Expressions made Strangely Simple'
FormatsToProcess = 'Irregular.format.ps1xml'
Expand All @@ -14,6 +14,12 @@
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.4:
* ANSI Improvements:
* Regenerated ?<ANSI_Color> (Fixes #150)
* Added ?<ANSI_Cursor> (Fixes #151)
---
## 0.7.3:
* ANSI Improvements:
* Fixed ?<ANSI_Style> (Fixes #143)
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.3'>v 0.7.3 </a>
<a href='https://github.com/StartAutomating/Irregular/releases/tag/v0.7.4'>v 0.7.4 </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 130 useful [named expressions](SavedPatterns.md), and lets you create more.
Irregular comes with 131 useful [named expressions](SavedPatterns.md), and lets you create more.

To see the expressions that ship with Irregular, run:

Expand Down
48 changes: 29 additions & 19 deletions RegEx/ANSI/Color.regex.txt
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
# 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
(?-i)\e # An Escape
\[ # Followed by a bracket
(?>
(?<IsForegroundColor>38) |
(?<IsBackgroundColor>48) |
(?<IsUnderlineColor>58));2;(?<Color>(?<Red>(?>[0-2][0-5][0-5]|[0-1]\d\d|\d{1,2})) # Red is the first 0-255 value
;(?<Green>(?>[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
(?-i)\e # An Escape
\[ # Followed by a bracket
(?>
(?<IsForegroundColor>38) |
(?<IsBackgroundColor>48) |
(?<IsUnderlineColor>58));5;(?<Color>(?>
(?<StandardColor>[0-7]) # 0 -7 are standard colors
m |
(?<BrightColor>(?>[8-9]|1[0-5])) # 8-15 are bright colors
(?<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
(?<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
(?<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)))
\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)
)
|
(?<ANSI_DefaultColor>
(?-i)\e # An Escape
\[ # Followed by a bracket
(?-i)\e # An Escape
\[ # Followed by a bracket
(?<Color>(?>
(?<DefaultForeground>39) # 39 Represents the default foreground color
(?<DefaultForeground>39) # 39 Represents the default foreground color
m |
(?<DefaultForeground>49) # 49 Represents the default background color
(?<DefaultForeground>49) # 49 Represents the default background color
m))
)
)
64 changes: 64 additions & 0 deletions RegEx/ANSI/Cursor.regex.source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
$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 cursor control" |
New-RegEx -CharacterClass Escape |
New-RegEx -LiteralCharacter '[' |
New-RegEx -Atomic -Or @(
New-RegEx -Pattern '6n' -Name 'DeviceStatusReport' -Comment '6n will request the cursor position'
New-RegEx -Pattern (
New-RegEx -Name Row -Pattern '\d+' |
New-RegEx -LiteralCharacter ';' |
New-RegEx -Name Column -Pattern '\d+' |
New-RegEx -Pattern 'R'
) -Comment "A Device Status Report will return CursorPosition in the form <row>;<column> R" -Name CursorPosition
New-RegEx -Name CursorUp -Comment "Cursor Up is a digit followed by A" -Pattern (
New-RegEx -Name RowCount -Pattern '\d+' |
New-RegEx -Pattern 'A'
)
New-RegEx -Name CursorDown -Comment "Cursor Down is a digit followed by B" -Pattern (
New-RegEx -Name RowCount -Pattern '\d+' |
New-RegEx -Pattern 'B'
)
New-RegEx -Name CursorForward -Comment "Cursor Forward is a digit followed by C" -Pattern (
New-RegEx -Name ColumnCount -Pattern '\d+' |
New-RegEx -Pattern 'C'
)
New-RegEx -Name CursorBack -Comment "Cursor Back is a digit followed by D" -Pattern (
New-RegEx -Name ColumnCount -Pattern '\d+' |
New-RegEx -Pattern 'D'
)
New-RegEx -Name CursorNextLine -Comment "Cursor Next Line is a digit followed by E" -Pattern (
New-RegEx -Name LineCount -Pattern '\d+' |
New-RegEx -Pattern 'E'
)
New-RegEx -Name CursorNextLine -Comment "Cursor Next Line is a digit followed by F" -Pattern (
New-RegEx -Name LineCount -Pattern '\d+' |
New-RegEx -Pattern 'F'
)
New-RegEx -Name CursorAbsolute -Comment "Cursor Absolute Position is a digit followed by G" -Pattern (
New-RegEx -Name AbsolutePosition -Pattern '\d+' |
New-RegEx -Pattern 'G'
)
New-RegEx -Name CursorPosition -Comment "Cursor Positions are two optional digits, separated by semicolon, ending with H" -Pattern (
New-RegEx -Name Row -Pattern '\d{0,}' |
New-RegEx -LiteralCharacter ';' |
New-RegEx -Name Column -Pattern '\d{0,}' |
New-RegEx -LiteralCharacter 'H'
)
New-RegEx -Name ScrollUp -Comment "Scroll Up is a digit followed by S" -Pattern (
New-RegEx -Name PageCount -Pattern '\d+' |
New-RegEx -Pattern 'S'
)
New-RegEx -Name ScrollDown -Comment "Scroll Down is a digit followed by T" -Pattern (
New-RegEx -Name PageCount -Pattern '\d+' |
New-RegEx -Pattern 'T'
)
New-RegEx -Name CursorHide -Comment 'Cursors can be hidden with 25h' (
New-RegEx -Pattern '25h'
)
New-RegEx -Name CursorShow -Comment 'Cursors can be hidden with 25l' (
New-RegEx -Pattern '25l'
)
) |
Set-Content -Path (Join-Path $myRoot $myName) -PassThru
30 changes: 30 additions & 0 deletions RegEx/ANSI/Cursor.regex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Matches an ANSI cursor control
\e\[(?>
(?<DeviceStatusReport>6n) # 6n will request the cursor position
|
(?<CursorPosition>(?<Row>\d+)\;(?<Column>\d+)R) # A Device Status Report will return CursorPosition in the form <row>;<column> R
|
(?<CursorUp>(?<RowCount>\d+)A) # Cursor Up is a digit followed by A
|
(?<CursorDown>(?<RowCount>\d+)B) # Cursor Down is a digit followed by B
|
(?<CursorForward>(?<ColumnCount>\d+)C) # Cursor Forward is a digit followed by C
|
(?<CursorBack>(?<ColumnCount>\d+)D) # Cursor Back is a digit followed by D
|
(?<CursorNextLine>(?<LineCount>\d+)E) # Cursor Next Line is a digit followed by E
|
(?<CursorNextLine>(?<LineCount>\d+)F) # Cursor Next Line is a digit followed by F
|
(?<CursorAbsolute>(?<AbsolutePosition>\d+)G) # Cursor Absolute Position is a digit followed by G
|
(?<CursorPosition>(?<Row>\d{0,})\;(?<Column>\d{0,})H) # Cursor Positions are two optional digits, separated by semicolon, ending with H
|
(?<ScrollUp>(?<PageCount>\d+)S) # Scroll Up is a digit followed by S
|
(?<ScrollDown>(?<PageCount>\d+)T) # Scroll Down is a digit followed by T
|
(?<CursorHide>25h) # Cursors can be hidden with 25h
|
(?<CursorShow>25l) # Cursors can be hidden with 25l
)
1 change: 1 addition & 0 deletions RegEx/ANSI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Note: Using these regular expressions in the terminal may result in awkward out
|[?<ANSI_Bold>](Bold.regex.txt) |Matches an ANSI Bold Start or End |[source](Bold.regex.source.ps1) |
|[?<ANSI_Code>](Code.regex.txt) |Matches an ANSI escape code |[source](Code.regex.source.ps1) |
|[?<ANSI_Color>](Color.regex.txt) |Matches an ANSI color |[source](Color.regex.source.ps1) |
|[?<ANSI_Cursor>](Cursor.regex.txt) |Matches an ANSI cursor control |[source](Cursor.regex.source.ps1) |
|[?<ANSI_DefaultColor>](DefaultColor.regex.txt) |Matches an ANSI 24-bit color |[source](DefaultColor.regex.source.ps1) |
|[?<ANSI_Faint>](Faint.regex.txt) |Matches an ANSI Faint (aka dim) Start or End |[source](Faint.regex.source.ps1) |
|[?<ANSI_Hide>](Hide.regex.txt) |Matches ANSI Hide (aka conceal) Start or End |[source](Hide.regex.source.ps1) |
Expand Down
3 changes: 2 additions & 1 deletion SavedPatterns.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### Irregular Patterns
Irregular includes 130 regular expressions
Irregular includes 131 regular expressions
|Name|Description|IsGenerator|
|:---|:----------|:----------|
|[ANSI_24BitColor](/RegEx/ANSI/24BitColor.regex.txt)|Matches an ANSI 24-bit color|False|
Expand All @@ -9,6 +9,7 @@ Irregular includes 130 regular expressions
|[ANSI_Bold](/RegEx/ANSI/Bold.regex.txt)|Matches an ANSI Bold Start or End|False|
|[ANSI_Code](/RegEx/ANSI/Code.regex.txt)|Matches an ANSI escape code|False|
|[ANSI_Color](/RegEx/ANSI/Color.regex.txt)|Matches an ANSI color|False|
|[ANSI_Cursor](/RegEx/ANSI/Cursor.regex.txt)|Matches an ANSI cursor control|False|
|[ANSI_DefaultColor](/RegEx/ANSI/DefaultColor.regex.txt)|Matches an ANSI 24-bit color|False|
|[ANSI_Faint](/RegEx/ANSI/Faint.regex.txt)|Matches an ANSI Faint (aka dim) Start or End|False|
|[ANSI_Hide](/RegEx/ANSI/Hide.regex.txt)|Matches ANSI Hide (aka conceal) Start or End|False|
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.7.4:
* ANSI Improvements:
* Regenerated ?<ANSI_Color> (Fixes #150)
* Added ?<ANSI_Cursor> (Fixes #151)
---

## 0.7.3:
* ANSI Improvements:
* Fixed ?<ANSI_Style> (Fixes #143)
Expand Down
2 changes: 1 addition & 1 deletion docs/Export-RegEx.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ If the command sets a ```[ConfirmImpact("Medium")]``` which is lower than ```$co
---
### Syntax
```PowerShell
Export-RegEx [[-Name] &lt;String[]&gt;] [[-Path] &lt;String&gt;] [[-As] &lt;String&gt;] [[-Noun] &lt;String&gt;] [-WhatIf] [-Confirm] [&lt;CommonParameters&gt;]
Export-RegEx [[-Name] <String[]>] [[-Path] <String>] [[-As] <String>] [[-Noun] <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
```
---
### Notes
Expand Down
16 changes: 9 additions & 7 deletions docs/Get-RegEx.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ Get-RegEx -Name NextWord
@(Get-RegEx | # Gets all saved Regular Expressions as a Markdown table
Sort-Object Name |
ForEach-Object -Begin {
&#39;|Name|Description|IsGenerator|&#39;
&#39;|:---|:----------|:----------|&#39;
'|Name|Description|IsGenerator|'
'|:---|:----------|:----------|'
} -Process {
$desc = $_.Description -replace &#39;[\[\{\(]&#39;, &#39;\$0&#39;
$desc= if ($desc) {$desc | ?&lt;NewLine&gt; -Replace &#39;&lt;br/&gt;&#39;} else { &#39;&#39;}
&quot;|$($_.Name)|$desc|$($_.IsGenerator)|&quot;
$desc = $_.Description -replace '[\[\{\(]', '\$0'
$desc= if ($desc) {$desc | ?<NewLine> -Replace '<br/>'} else { ''}
"|$($_.Name)|$desc|$($_.IsGenerator)|"
}) -join [Environment]::NewLine
```

Expand Down Expand Up @@ -152,13 +152,15 @@ It prevents name conflicts with Irregular.

---
### Outputs
System.Management.Automation.PSObject
* [Management.Automation.PSObject](https://learn.microsoft.com/en-us/dotnet/api/System.Management.Automation.PSObject)




---
### Syntax
```PowerShell
Get-RegEx [[-Name] &lt;String[]&gt;] [[-FilePath] &lt;String[]&gt;] [[-FromModule] &lt;String[]&gt;] [[-As] &lt;String&gt;] [[-Noun] &lt;String&gt;] [&lt;CommonParameters&gt;]
Get-RegEx [[-Name] <String[]>] [[-FilePath] <String[]>] [[-FromModule] <String[]>] [[-As] <String>] [[-Noun] <String>] [<CommonParameters>]
```
---

Expand Down
8 changes: 5 additions & 3 deletions docs/Import-RegEx.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,18 @@ If set, will output the imported regular expressions.

---
### Outputs
System.Nullable
* [Nullable](https://learn.microsoft.com/en-us/dotnet/api/System.Nullable)


* [Management.Automation.PSObject](https://learn.microsoft.com/en-us/dotnet/api/System.Management.Automation.PSObject)


System.Management.Automation.PSObject


---
### Syntax
```PowerShell
Import-RegEx [[-FilePath] &lt;String[]&gt;] [[-FromModule] &lt;String[]&gt;] [[-Pattern] &lt;String[]&gt;] [[-Name] &lt;String[]&gt;] [-PassThru] [&lt;CommonParameters&gt;]
Import-RegEx [[-FilePath] <String[]>] [[-FromModule] <String[]>] [[-Pattern] <String[]>] [[-Name] <String[]>] [-PassThru] [<CommonParameters>]
```
---

Expand Down
22 changes: 12 additions & 10 deletions docs/New-RegEx.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ New-RegEx -CharacterClass Digit -Repeat -Name Digits

#### EXAMPLE 3
```PowerShell
# A regular expression for a quoted string (with \&quot; and `&quot; as valid escape sequences)
New-RegEx -Pattern &#39;&quot;&#39; |
# A regular expression for a quoted string (with \" and `" as valid escape sequences)
New-RegEx -Pattern '"' |
New-RegEx -CharacterClass Any -Repeat -Lazy -Before (
New-RegEx -Pattern &#39;&quot;&#39; -NotAfter &#39;\\|`&#39;
New-RegEx -Pattern '"' -NotAfter '\\|`'
) |
New-RegEx -Pattern &#39;&quot;&#39;
New-RegEx -Pattern '"'
```

#### EXAMPLE 4
Expand All @@ -59,9 +59,9 @@ New-RegEx -Description "Matches an Email Address" |
#### EXAMPLE 5
```PowerShell
# Writes a pattern for multiline comments
New-RegEx -Pattern \&lt;\# |
New-RegEx -Name Block -Until \#\&gt; |
New-RegEx -Pattern \#\&gt;
New-RegEx -Pattern \<\# |
New-RegEx -Name Block -Until \#\> |
New-RegEx -Pattern \#\>
```

---
Expand Down Expand Up @@ -1137,16 +1137,18 @@ A list of arguments. These are only valid if the regex is using a Generator scr

---
### Outputs
System.Text.RegularExpressions.Regex
* [Text.RegularExpressions.Regex](https://learn.microsoft.com/en-us/dotnet/api/System.Text.RegularExpressions.Regex)


* [Management.Automation.PSObject](https://learn.microsoft.com/en-us/dotnet/api/System.Management.Automation.PSObject)


System.Management.Automation.PSObject


---
### Syntax
```PowerShell
New-RegEx [[-Pattern] &lt;String[]&gt;] [-Name &lt;String&gt;] [-CharacterClass &lt;String[]&gt;] [-LiteralCharacter &lt;String[]&gt;] [-UnicodeCharacter &lt;Int32[]&gt;] [-ExcludeCharacterClass &lt;String[]&gt;] [-ExcludeLiteralCharacter &lt;String[]&gt;] [-ExcludeUnicodeCharacter &lt;Int32[]&gt;] [-DigitMax &lt;UInt32&gt;] [-Backreference &lt;String&gt;] [-NotAfter &lt;String&gt;] [-NotBefore &lt;String&gt;] [-After &lt;String&gt;] [-Before &lt;String&gt;] [-Repeat] [-Greedy] [-Lazy] [-Min &lt;Int32&gt;] [-Max &lt;Int32&gt;] [-If &lt;String&gt;] [-Then &lt;String[]&gt;] [-Else &lt;String[]&gt;] [-Until &lt;String[]&gt;] [-Comment &lt;String&gt;] [-Description &lt;String&gt;] [-Not] [-Or] [-StartAnchor &lt;String&gt;] [-EndAnchor &lt;String&gt;] [-Modifier &lt;String[]&gt;] [-Optional] [-Atomic] [-NoCapture] [-PrePattern &lt;String[]&gt;] [-TimeOut &lt;TimeSpan&gt;] [-Between &lt;String[]&gt;] [-EscapeSequence &lt;String&gt;] [-Denormalized] [-Parameter &lt;IDictionary&gt;] [-ArgumentList &lt;PSObject[]&gt;] [&lt;CommonParameters&gt;]
New-RegEx [[-Pattern] <String[]>] [-Name <String>] [-CharacterClass <String[]>] [-LiteralCharacter <String[]>] [-UnicodeCharacter <Int32[]>] [-ExcludeCharacterClass <String[]>] [-ExcludeLiteralCharacter <String[]>] [-ExcludeUnicodeCharacter <Int32[]>] [-DigitMax <UInt32>] [-Backreference <String>] [-NotAfter <String>] [-NotBefore <String>] [-After <String>] [-Before <String>] [-Repeat] [-Greedy] [-Lazy] [-Min <Int32>] [-Max <Int32>] [-If <String>] [-Then <String[]>] [-Else <String[]>] [-Until <String[]>] [-Comment <String>] [-Description <String>] [-Not] [-Or] [-StartAnchor <String>] [-EndAnchor <String>] [-Modifier <String[]>] [-Optional] [-Atomic] [-NoCapture] [-PrePattern <String[]>] [-TimeOut <TimeSpan>] [-Between <String[]>] [-EscapeSequence <String>] [-Denormalized] [-Parameter <IDictionary>] [-ArgumentList <PSObject[]>] [<CommonParameters>]
```
---

Expand Down
Loading

0 comments on commit 7abe0ff

Please sign in to comment.