Reputation: 11
I am just learning powershell and cant find how to run differents regex with powershell.
$input_path = 'C:\site-download\input.txt'
$output_file = 'C:\site-download\output.txt'
$regex = '(?<month>VPIP<\/span><span class=""right"">\d{2}.\d{1})'
$regex2 = '(?<month>VPIP<\/span><span class=""right"">\d{2}.\d{1})'
$regex3 = '(?<month>VPIP<\/span><span class=""right"">\d{2}.\d{1})'
$regex... = '(?<month>VPIP<\/span><span class=""right"">\d{2}.\d{1})'
select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches} | % { $_.Value }|
Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} > $output_file
$regex
works good, but how can i add $regex2
and $regex3
... to outputfile?
Thanks
Upvotes: 0
Views: 152
Reputation:
You just need a small change to your last section of your pipeline. Instead of using > $output_file
just pipe the output of the foreach
loop to Out-File
cmdlet. So you should be able to have your last line of code look like this:
select-string -Path $input_path -Pattern $regex -AllMatches |
% { $_.Matches} | % { $_.Value } |
Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} |
Out-File $output_file
Upvotes: 1