Skip to content

Commit

Permalink
Adding ?<Degrees> (Fixes #185)
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Apr 13, 2023
1 parent b2c9874 commit c8c0419
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions RegEx/Degrees.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 "Matching degrees" |
New-Regex -Pattern ?<Decimals> |
New-RegEx -CharacterClass Whitespace -Min 0 -Comment "Optional Whitespace" |
New-RegEx -Atomic -Or @("Degrees","Degree", "°") -Comment "Degree(s) or the degree symbol" |
New-RegEx -CharacterClass Whitespace -Min 0 -Comment "Optional Whitespace" |
New-RegEx -Name UnitType -Optional -Pattern $(
New-RegEx -Atomic -Or @(
"Celsius"
"C"
"Fahrenheit"
"F"
)
) -Comment "Optional unit" |
Set-Content -Path (Join-Path $myRoot $myName)



27 changes: 27 additions & 0 deletions RegEx/Degrees.regex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Matching degrees
(?<Decimals>
(?<IsNegative>\-)? # It might be start with a -
(?:(?> # Then it can be either:
(?<Characteristic>\d+) # One or more digits (the Characteristic)
(?:\.(?<Mantissa>\d+)){0,1} # followed by a period and one or more digits (the Mantissa)
| # Or it can be
(?:\.(?<Mantissa>\d+)) # just a Mantissa
))
(?:
E
(?<Exponent>
[+-]\d+
)
)?
)
\s{0,} # Optional Whitespace
(?>
Degrees |
Degree |
°) # Degree(s) or the degree symbol
(?<UnitType>(?>
Celius |
C |
Fahrenheit |
F))? # Optional unit

0 comments on commit c8c0419

Please sign in to comment.