【发布时间】:2020-09-14 18:01:30
【问题描述】:
在此示例中,我似乎无法让 sed 使用组捕获进行正则表达式替换:
- 输入:“完成项目 1”
- 所需的 putput:“project 1 DONE”
我对@987654322@ 的尝试:
$ echo "DONE project 1" | sed -E 's/^DONE(.*)$/$1 DONE/g'
$1 DONE # fail! no group capture in `sed`?
Perl 有没有办法做到这一点?
实际上这是 DEVONthink[^1] 使用的 AppleScript 的一部分,我意识到 sed 无法使用组捕获进行正则表达式搜索/替换。
[^1]:DEVONthink 使用 AppleScript 搜索/替换脚本
set transformedName to do shell script "echo " & quoted form of itemName & " | sed -E 's/" & sourcePattern & "/" & destPattern & "/g'"
set name of selectedItem to transformedName
【问题讨论】: