Copy all regex matched items using powershell

$text = cat file.txt
$regex = [regex] ‘your regex’
$match = $regex.Match($text)
$result = “”
while($match.Success)
{
$result = $result + $match.Value + “`r`n”
$match = $match.NextMatch()
}
$result | Out-File result.txt

Leave a Reply

Your email address will not be published. Required fields are marked *