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


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


 
 

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

$content="[AutoProxy 0.2.9]"

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

结果是[]
 

 
 

1 Answers
1
Best Answer
周蒙牛 answered 7 年 ago

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