繁体   English   中英

如何多次正则表达式PowerShell

[英]How to regex multiple times powershell

我只是在学习powershell,无法找到如何使用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效果很好,但是如何将$regex2$regex3 ...添加到outputfile?

谢谢

您只需要对管道的最后一部分进行少量更改。 而不是使用> $output_file而是将foreach循环的输出通过管道传递到Out-File cmdlet。 因此,您应该能够使最后一行代码如下所示:

select-string -Path $input_path -Pattern $regex -AllMatches | 
    % { $_.Matches} | % { $_.Value } |
    Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} | 
    Out-File $output_file

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM