I am starting from this example in JavaScript, and trying to do the same performance test.
I have
$string = 'RAM Statistics: 5954 / 8174 743=InUse 746=Peak'
$RegEx1 = '/ +/g'
$RegEx2 = '/ +/g'
$RegEx3 = '/ {2,}/g'
$RegEx4 = '/\s\s+/g'
$RegEx5 = '/ +(?= )/g'
Measure-Command {
$newString = $string -replace $RegEx1, $null
}
Write-Host "$newString"
Measure-Command {
$newString = $string -replace $RegEx2, $null
}
Write-Host "$newString"
Measure-Command {
$newString = $string -replace $RegEx3, $null
}
Write-Host "$newString"
Measure-Command {
$newString = $string -replace $RegEx4, $null
}
Write-Host "$newString"
Measure-Command {
$newString = $string -replace $RegEx5, $null
}
Write-Host "$newString"
and I am getting very different times, but all return nothing, which isn't exactly useful. Where am I going wrong translating Javascript RegEx to PowerShell Regex? FWIW, I want to keep things simple, so spaces only, no need to also replace CR and the like. The data is pretty simple, the formatting is just junk.