小编hmn*_*nzr的帖子

Powershell正则表达式组取代

我想替换文件夹中每个脚本文件中的一些文本,我正在尝试使用此PS代码:

$pattern = '(FROM [a-zA-Z0-9_.]{1,100})(?<replacement_place>[a-zA-Z0-9_.]{1,7})'
Get-ChildItem -Path 'D:\Scripts' -Recurse -Include *.sql | ForEach-Object { (Get-Content $_.fullname) -replace $pattern, 'replace text' | Set-Content $_.fullname }
Run Code Online (Sandbox Code Playgroud)

但我不知道如何保留表达式的第一部分,而只是替换第二部分.知道我该怎么办?谢谢.

regex powershell replace

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

powershell ×1

regex ×1

replace ×1