亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

更改對列表重新編號的 Javascript 代碼

更改對列表重新編號的 Javascript 代碼

撒科打諢 2022-12-29 10:30:11
我不熟悉 Javascript,但我想更改以下代碼。目前,它以 01)、02) 等格式重命名程序 Keyboard Maestro 中的宏。我希望它只使用數字后跟空格的格式(即 1 、 2 等)我希望我描述的是有道理的。謝謝!第1部分:(function(inDesignMode) {'use strict';function dump(obj, desc) {    console.log((desc ? desc + ": " : "") + JSON.stringify(obj, null, "\t"));}var KMEditor = (function() {    var _editorAppName = "Keyboard Maestro";    var _editorApp;    return {        getEditorApp: function() {            return _editorApp ? _editorApp : _editorApp = Application(_editorAppName);        getEditorAppName: function() {return _editorAppName;},        getSelectedMacrosOrGroups: function() {            return this.getEditorApp().selectedmacros();        }    };})();var KMEngine = (function() {    var _engineApp;    return {        getAllMacrosSourceFileName: function() {            return this.getAppSupportFolderName() + "Keyboard Maestro Macros.plist";        },        getAppSupportFolderName: function() {            var app = Application.currentApplication();            app.includeStandardAdditions = true;            return app.pathTo('application support', { from: 'user domain' }) +                "/Keyboard Maestro/";        },        getEngineAppName: function() {            return "Keyboard Maestro Engine";        },        getEngineApp: function() {            if (!_engineApp)                _engineApp = Application(this.getEngineAppName());            return _engineApp;        },        readPlistBinaryFile: function(path) {            var data = $.NSData.dataWithContentsOfFile(path);            return ObjC.deepUnwrap(                $.NSPropertyListSerialization.propertyListWithDataOptionsFormatError(                    data, $.NSPropertyListBinaryFormat_v1_0, 0, null));        },    };})();function getMacrosInfo(selectedMacroUUIDs) {    function getMacroName(macro) {        if (macro.Name)            return macro.Name;        throw Error("Un-named Macro UUID: " + macro.UID);    }
查看完整描述

1 回答

?
翻過高山走不出你

TA貢獻1875條經驗 獲得超3個贊

根據您的評論中獲得的澄清,這就是您需要的:

01)macro-->1 macro

為此,您可以嘗試execute()在第 2 部分的函數中添加以下行:

const regExp = /^0(.)\)/i; //Creates the regular expression
newName.replace(regex, '$1 '); //Replaces the match from the regex with a substring
macro.name = newName;

這是一個正則表達式子字符串替換(此處有更多詳細信息)。這是正在做的事情的細目分類。

^符號表示正在從字符串的開頭搜索子字符串。

接下來只是在字符串開頭對0a 進行字面搜索。0

接下來(開始一個帶括號的子匹配字符串,稍后將解釋其用途。

.表示任何單個字符。

帶括號的子匹配字符串的下一個)結尾較早開始。

接下來\)是搜索)需要轉義的字面值,\因為如上所述,)它具有結束帶括號的子匹配字符串的特殊含義。

現在,使用帶括號的子匹配字符串,以便在與正則表達式匹配后,結果可以進一步用于替換匹配的字符串。在這種情況下,

01)macro1作為帶括號的子匹配字符串匹配,因為它是前導 0 之后和 . 之前的單個字符)。這$1在 replace 函數中使用,以便在 matching 之后01),它被替換為1 (注意額外的空間,這是問題所要求的)。


查看完整回答
反對 回復 2022-12-29
  • 1 回答
  • 0 關注
  • 96 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號