Pau*_*osa 1 regex extjs sublimetext3
我有一个过程,涉及创建类似的文件/文件名结构,其中包含其自身的名称,以及类似的事情,我每天都这样做,我发现这是重复的并且有一个模式,然后我想到了创建 Sublime Text 的片段来为我生成代码,这对我的性能有显着的提高。
\n有一个使用我所说的结构的完整“模型”的示例:
\nExt.define(\'App.model.geral.layouts.Layouts\', {\n extend: \'App.ux.model.base\',\n\n fields: [\n { name: \'Foo\', type: \'string\', fieldLabel: \'Foo\' },\n { name: \'Bar\', type: \'int\', fieldLabel: \'Bar\' },\n { name: \'FooTwo\', type: \'boolean\', fieldLabel: \'FooTwo\' },\n { name: \'Date\', type: \'date\', fieldLabel: \'Date\' },\n ],\n \n proxy: Use.util.Model.getProxy({\n controller: \'Layouts\'\n })\n});\n
Run Code Online (Sandbox Code Playgroud)\n这是使用我的结构的文件的简单小样本。因此,遵循模式的该文件将被放置在C:/Dev/Com/app/model/geral/layouts/Layouts.js
,因为 models 位于文件夹model内,而geral是实体布局所属的模块。
我尝试了各种方法,最远的是那个片段文件:
\n<snippet>\n <content><![CDATA[\nExt.define(\'App.model.${TM_FILEPATH/.+(?:model\\/)(.+)\\.\\w+/\\l$1/}\', {\n extend: \'\',\n\n fields: [ ],\n\n proxy: \'\' \n});\n]]></content>\n <tabTrigger>mitem</tabTrigger>\n</snippet>\n
Run Code Online (Sandbox Code Playgroud)\nC:/Dev/Com/app/model/geral/layouts/Layouts.js
当我在名为并位于:(作为模式)的空文件上触发该片段时,结果是:
<snippet>\n <content><![CDATA[\nExt.define(\'App.model.${TM_FILEPATH/.+(?:model\\/)(.+)\\.\\w+/\\l$1/}\', {\n extend: \'\',\n\n fields: [ ],\n\n proxy: \'\' \n});\n]]></content>\n <tabTrigger>mitem</tabTrigger>\n</snippet>\n
Run Code Online (Sandbox Code Playgroud)\n正如你所看到的,我得到的\'App.model.geral/layouts/Layouts\'
并不是\'App.model.geral.layouts.Layouts\'
我想要的。我已经接近我想要的最终结果,正如您在完整的模型示例中看到的那样,顺便说一句,我不能走得太远,我对 RegExp 没有任何了解,我所做的只是研究和尝试不同的事情。
如果有帮助,我发现有关 Sublime Snippets 的更完整信息是:
\n$PARAM1 .. $PARAMn Arguments passed to the insert_snippet command. (Not covered here.)\n$SELECTION The text that was selected when the snippet was triggered.\n$TM_CURRENT_LINE Content of the cursor\xe2\x80\x99s line when the snippet was triggered.\n$TM_CURRENT_WORD Word under the cursor when the snippet was triggered.\n$TM_FILENAME Name of the file being edited, including extension.\n$TM_FILEPATH Path to the file being edited.\n$TM_FULLNAME User\xe2\x80\x99s user name.\n$TM_LINE_INDEX Column where the snippet is being inserted, 0 based.\n$TM_LINE_NUMBER Row where the snippet is being inserted, 1 based.\n$TM_SELECTED_TEXT An alias for $SELECTION.\n$TM_SOFT_TABS YES if translate_tabs_to_spaces is true, otherwise NO.\n$TM_TAB_SIZE Spaces per-tab (controlled by the tab_size option).\n
Run Code Online (Sandbox Code Playgroud)\n我使用该信息来获取文件路径,我尝试使用其他变量,例如文件名,但没有达到那么远。
\n如果有人可以帮助我得到最终结果,那将非常有用。
\n您可以通过以下方式实现您想要的:
<snippet>
<content><![CDATA[
Ext.define('App.model.${TM_FILEPATH/(^.+\/model\/)|(\w+)|(\.\w+$)|(\/)/(?2$2)(?4.)/g}', {
extend: '',
fields: [ ],
proxy: ''
});
]]></content>
<tabTrigger>mitem</tabTrigger>
</snippet>
Run Code Online (Sandbox Code Playgroud)
顺便说一句,如果您还没有
安装PackageDev 包,我强烈建议您安装,以便在代码片段和正则表达式/替换上获得一些语法突出显示。
(^.+\/model\/)
匹配从文件路径开头一直到(包括)的内容/model/
,并存储在捕获组 1 中|
或者(\w+)
匹配任何单词字符序列并存储在捕获组 2 中|
或者(\.\w+$)
匹配文件扩展名并存储在捕获组 3 中|
或者(\/)
匹配 a/
并存储在捕获组 4 中(?2$2)
如果捕获组 2 参加了比赛,则将其替换为自身 - 即保留它(?4.)
如果捕获组 4 参加了比赛,则将其替换为点g
全局修饰符匹配尽可能多的次数可以说您不需要捕获组 1 和 3,但我将它们包括在内是为了更容易判断正在匹配的内容。
归档时间: |
|
查看次数: |
705 次 |
最近记录: |