单引号里面的内容不是不会被转义吗? 为什么我的[]没有被替换掉


PowerShell交流中心 › 分类: Questions › 单引号里面的内容不是不会被转义吗? 为什么我的[]没有被替换掉
0 赞 踩
周蒙牛 asked 9 年 ago


 
 

单引号里面的内容不是不会被转义吗?

$content="[AutoProxy 0.2.9]"

$content = $content -replace '[AutoProxy 0.2.9]', ''
$content

结果是[]
 

 
 

1 Answers
1 赞 踩
Best Answer
周蒙牛 answered 9 年 ago

`-replace` 解析正则会转义, 不区分大小写
powershell won’t do $Var replacement on single quote strings,
but you need to escape again for the regex engine.
`$var.replace()` 不解析正则不转义, 区分大小写