powershell - 使用 powershell 替换链接中的字符

标签 powershell powershell-2.0 powershell-3.0

我想替换 ?

"EquipmentInfo["?"] = "<iframe src='http://bing.fr'></iframe>";"

通过变量。

我尝试过这个:

(get-content C:\word.txt) -replace '?', '$obj' | Set-Content C:\word.txt

最佳答案

我会使用积极的回顾来确保您找到正确的问号。此外,您还必须在替换项上使用双引号,因为您想替换变量:

(get-content C:\word.txt -raw) -replace '(?<=EquipmentInfo\[")\?', "$obj" | Set-Content C:\word.txt

使用的正则表达式:

(?<=EquipmentInfo\[")\?

Regular expression visualization

关于powershell - 使用 powershell 替换链接中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37679977/

相关文章:

powershell - 如何在 PowerShell 中写入标准错误?

powershell - 如何使用 ps1 脚本打开 image.png?

powershell - 合并文本文件并添加文件名和行号 - Powershell

powershell - 如何从大量文件夹中删除单个用户 ACL?

function - 获取 .ps1 文件中特定函数的最后一行

Azure Devops Powershell 不显示 Get-ChildItem 的文件名

powershell - 多个-ne滤波器Powershell

powershell - PowerShell从samAccountNames的csv创建AD用户和属性的列表

powershell - 了解Powershell try catch

Powershell - 获取 WinEvent