Using Windows PowerShell 5.1, EndsWith() and -like are almost twice as fast as RegEx, across 100,000 iterations each (using the code below). TheDammedGamer
RegEx method: 295 ms
EndsWith method: 189 ms
Like method: 160 ms
using namespace System.Diagnostics
$stopwatch = [Stopwatch]::StartNew();
for ($i = 0; $i -lt 100000; $i++) {
$boolValue = 'something\' -match '\\$'
}
"RegEx method: $($stopwatch.ElapsedMilliseconds) ms "
$stopwatch = [Stopwatch]::StartNew();
for ($i = 0; $i -lt 100000; $i++) {
$boolValue = 'something\'.EndsWith('\')
}
"EndsWith method: $($stopwatch.ElapsedMilliseconds) ms "
$stopwatch = [Stopwatch]::StartNew();
for ($i = 0; $i -lt 100000; $i++) {
$boolValue = 'something\' -like '*\'
}
"Like method: $($stopwatch.ElapsedMilliseconds) ms "