Powershell script and regexp filtering

49 Views Asked by At

Here's the PowerShell snippet:

$regex = ".*[A-Z a-z][ \t]{3,}"
$file = 'C:\temp\log\log.json'

Get-Content $file2) | ForEach-Object {
    $_.replace('{"time": "', "").
    replace($regex, "")

} | Out-File $file

I tested the regex, and it works on the RegExr site.

2018-01-10T14:37:08981+00:00 WindowsFeature Storage-Services --> match
2020-01-10T14:37:08997+00:00 WindowsFeature Storage-Services --> match 2020-01-10T14:37:09059+00:00 WindowsFeature Storage-Services The operation 'Get-WindowsFeature' started: Storage-Services 2018-01-10T14:37:09934+00:00 WindowsFeature Storage-Services The operation 'Get-WindowsFeature' succeeded: Storage-Services

The first replacement has been successfully completed, but the second no longer.

0

There are 0 best solutions below