文本編輯器UltraEdit的一樣替換操作過程中不支持公式求值。這需要腳本和腳本解釋器,比如Perl或JavaScript。
UltraEdit內置了JavaScript解釋器。因此,使用UltraEdit腳本的UltraEdit也可以完成此任務,例如下面的腳本。其文檔中
if (UltraEdit.document.length > 0) // Is any file opened?
{
// Define environment for this script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
// Move caret to top of the active file.
UltraEdit.activeDocument.top();
// Defined all Perl regular expression Find parameters.
UltraEdit.perlReOn();
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=true;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=true;
UltraEdit.activeDocument.findReplace.searchDown=true;
if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
{
UltraEdit.activeDocument.findReplace.searchInColumn=false;
}
// Search for each number after case-sensitive word DATA using
// a look-behind to get just the number selected by the find.
// Each backslash in search string for Perl regular expression
// engine of UltraEdit must be escaped with one more backslash as
// the backslash is also the escape character in JavaScript strings.
while(UltraEdit.activeDocument.findReplace.find("(?<=\\bDATA)\\d+"))
{
// Convert found and selected string to an integer using decimal
// system, increment the number by eight, convert the incremented
// number back to a string using again decimal system and write the
// increased number string to file overwriting the selected number.
var nNumber = parseInt(UltraEdit.activeDocument.selection,10) + 8;
UltraEdit.activeDocument.write(nNumber.toString(10));
}
}
我不明白Perl是如何在所有與此相關的工具,但也有發現的例子/替換:http://www.ultraedit.com/support/tutorials_power_tips/ultraedit/regular_expressions .html –
@Hunter:它支持3種正則表達式(Ultraedit,Unix和Perl),我特別使用Perl正則表達式樣式。鏈接中的示例非常有用,但特別缺乏修改捕獲的組的能力,這是我的問題。我現在可能根本無法做到。 –