所以我有大约 100 个不同类型的文件,这些文件包含以下字符串:
1.2.0.0
和
1,2,0,0
我只是想用 1.2.0.1 替换 1.2.0.0,只有带点的字符串,但 powershell 也会替换这些字符串 1,2 ,0,0 与 1.2.0.0 为什么 Powershell 将逗号视为句号?
get-childitem $OUTPUT_PATH -recurse -include *.rc,*.cs,*.rtf,*.sql |
select -expand fullname |
foreach {
(Get-Content $_) -replace '1.2.0.0','1.2.0.1' | Set-Content $_
}
最佳答案
-replace
运算符使用正则表达式(请参阅help about_Comparison_Operators
)。正则表达式中的 .
表示“任何字符”。如果您指的是文字 .
,则需要使用 \
将其转义,如 \.
。例如:
'abc 1.2.0.0 def' -replace '1\.2\.0\.0', '1.2.0.1'
如果您不想使用正则表达式,请使用String
对象的Replace
方法。例如:
'abc 1.2.0.0 def'.Replace('1.2.0.0','1.2.0.1')
两者都会输出abc 1.2.0.1 def
。
关于c# - Powershell 替换功能在替换时将逗号视为点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35589776/