带有管道字符的字符串 - 如何避免它们被误认为逻辑OR?

时间:2013-06-29 14:06:30

标签: powershell

$word = '{Quit|Discontinue|Stop|Cease|Give Up}'
$htmltitle1 = $word -replace  '{Quit|Discontinue|Stop|Cease|Give Up}', 'Give Up' 

$ htmltitle1

Give Up|Give Up|Give Up|Give Up|Give Up

如何强制powershell将文本替换为精确字符串而不是逻辑OR?

应该是:

Give Up

感谢

1 个答案:

答案 0 :(得分:4)

$htmltitle1 = $word -replace [regex]::escape('{Quit|Discontinue|Stop|Cease|Give Up}'), 'Give Up'