Programming

Using PowerShell for Precise Matching

steloflute 2025. 10. 6. 22:54

Using PowerShell for Precise Matching

PowerShell provides better regex support and can directly extract matches:

$input_path = 'test.txt'
$regex = '[0-9]+ errors'
select-string -Path $input_path -Pattern $regex -AllMatches | ForEach-Object { $_.Matches.Value }​

This outputs only the matched strings, such as:

11 errors