首页 > 解决方案 > 在 PowerShell 中使用正则表达式替换多行字符串

问题描述

我正在尝试实现这一点,但它在 Notepad++ 中工作,但在 PowerShell+regex 中没有

文件:1.txt

1
2
3
4

PS:

(Get-Content E:\1.txt).replace("(?ms)1((?:.*\r?\n?)*)4", "success") | Set-Content E:\2.txt

我试过用?ms、?s 和?m。

有什么帮助吗?

标签: regexstringpowershellmultiline

解决方案


推荐阅读