加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式 – Powershell:使用正则表达式的-replace

发布时间:2020-12-14 05:49:30 所属栏目:百科 来源:网络整理
导读:如何使用正则表达式替换-replace语句的引号之间的任何文本?我可以使用静态文本,但它几乎可以是任何文本. 例: $filecontent -replace 'AssemblyCopyright("text")','AssemblyCopyright("Copyright ? 2016 myCompany")' | Out-File $file 鉴于AssemblyCopyri
如何使用正则表达式替换-replace语句的引号之间的任何文本?我可以使用静态文本,但它几乎可以是任何文本.

例:

$filecontent -replace 'AssemblyCopyright("text")','AssemblyCopyright("Copyright ? 2016 myCompany")' | Out-File $file

鉴于AssemblyCopyright(“text”)实际上可以包括空白

AssemblyCopyright("")

解决方法

试试吧

... -replace 'AssemblyCopyright("[^"]*")','AssemblyCopyright("Copyright ? 2016 myCompany")'

但请注意,这将假定引号内的文本不包含其他引用.

示例由于评论

GIF example

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读