Skip to content

Commit c8c0419

Browse files
author
James Brundage
committed
Adding ?<Degrees> (Fixes #185)
1 parent b2c9874 commit c8c0419

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

RegEx/Degrees.regex.source.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$myName = ($MyInvocation.MyCommand.ScriptBlock.File | Split-Path -Leaf) -replace '\.source', '' -replace '\.ps1', '.txt'
2+
$myRoot = $MyInvocation.MyCommand.ScriptBlock.File | Split-Path
3+
4+
New-RegEx -Description "Matching degrees" |
5+
New-Regex -Pattern ?<Decimals> |
6+
New-RegEx -CharacterClass Whitespace -Min 0 -Comment "Optional Whitespace" |
7+
New-RegEx -Atomic -Or @("Degrees","Degree", "°") -Comment "Degree(s) or the degree symbol" |
8+
New-RegEx -CharacterClass Whitespace -Min 0 -Comment "Optional Whitespace" |
9+
New-RegEx -Name UnitType -Optional -Pattern $(
10+
New-RegEx -Atomic -Or @(
11+
"Celsius"
12+
"C"
13+
"Fahrenheit"
14+
"F"
15+
)
16+
) -Comment "Optional unit" |
17+
Set-Content -Path (Join-Path $myRoot $myName)
18+
19+
20+

RegEx/Degrees.regex.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Matching degrees
2+
(?<Decimals>
3+
(?<IsNegative>\-)? # It might be start with a -
4+
(?:(?> # Then it can be either:
5+
(?<Characteristic>\d+) # One or more digits (the Characteristic)
6+
(?:\.(?<Mantissa>\d+)){0,1} # followed by a period and one or more digits (the Mantissa)
7+
| # Or it can be
8+
(?:\.(?<Mantissa>\d+)) # just a Mantissa
9+
))
10+
(?:
11+
E
12+
(?<Exponent>
13+
[+-]\d+
14+
)
15+
)?
16+
)
17+
\s{0,} # Optional Whitespace
18+
(?>
19+
Degrees |
20+
Degree |
21+
°) # Degree(s) or the degree symbol
22+
(?<UnitType>(?>
23+
Celius |
24+
C |
25+
Fahrenheit |
26+
F))? # Optional unit
27+

0 commit comments

Comments
 (0)