用 Applescript 和 BBEdit 替换字符串中的数字
Replacing numbers in a string with Applescript and BBEdit
我完全是个初学者,写了一些小脚本,这些脚本使用 Applescript 为 BBEdit 提供查找和替换字段列表,主要用于格式化。 IE。转换为 tag1、tag2 等
我正在尝试使用相同的方法来替换一些数字,所以找到 9 替换为 1。只有当数字的两边都有 space 时才有效。 IE。 tag9 9, 被替换为 tag9 1. 不知道有没有人能告诉我为什么?
这是我的脚本:
set line1replaceList to {{"0", "1"}, {"9", "1"}, {"8", "1"}, {"7", "1"}, {"6", "1"}, {"5", "1"}, {"4", "1"}, {"3", "1"}, {"2", "1"}}
tell application "BBEdit"
tell window 1
repeat with thePair in line1replaceList
replace (item 1 of thePair) using (item 2 of thePair) options {starting at top:true, case sensitive:false, match words:true, search mode:grep}
# Check the "Search Options" in TextWrangler's scipting dictionary!
end repeat
end tell
end tell
在此先感谢您的帮助。
汤姆
删除 "match words" 部分,它应该可以工作。事实上,您也不需要 grep 部分。
所以该行将是:
replace (item 1 of thePair) using (item 2 of thePair) options {starting at top:true, case sensitive:false}
我完全是个初学者,写了一些小脚本,这些脚本使用 Applescript 为 BBEdit 提供查找和替换字段列表,主要用于格式化。 IE。转换为 tag1、tag2 等
我正在尝试使用相同的方法来替换一些数字,所以找到 9 替换为 1。只有当数字的两边都有 space 时才有效。 IE。 tag9 9, 被替换为 tag9 1. 不知道有没有人能告诉我为什么?
这是我的脚本:
set line1replaceList to {{"0", "1"}, {"9", "1"}, {"8", "1"}, {"7", "1"}, {"6", "1"}, {"5", "1"}, {"4", "1"}, {"3", "1"}, {"2", "1"}}
tell application "BBEdit"
tell window 1
repeat with thePair in line1replaceList
replace (item 1 of thePair) using (item 2 of thePair) options {starting at top:true, case sensitive:false, match words:true, search mode:grep}
# Check the "Search Options" in TextWrangler's scipting dictionary!
end repeat
end tell
end tell
在此先感谢您的帮助。
汤姆
删除 "match words" 部分,它应该可以工作。事实上,您也不需要 grep 部分。
所以该行将是:
replace (item 1 of thePair) using (item 2 of thePair) options {starting at top:true, case sensitive:false}