IntelliJ 实时模板。删除或替换文件名开头的数字

IntelliJ live template. Remove or replace number at the beginning of filename

我有文件名开头带有时间戳的数据库迁移文件。例如: 1537865596694-create-config-table.migration.ts

可以使用表达式将文件名转换为 Typescript class 名称: capitalize(camelCase(fileNameWithoutExtension()))

但我找不到删除或替换号码的选项。

你可以试试groovyScript("groovy code")(见https://www.jetbrains.com/help/idea/2017.2/edit-template-variables-dialog.html#predefined_functions, http://bartololeo.blogspot.ru/2014/01/idea-12-how-to-write-live-template-with.html。喜欢:

groovyScript("def res=''; def fname=_editor.getVirtualFile().getNameWithoutExtension(); def index=fname.indexOf('-'); if
(index!=-1) res=fname.substring(index+1, fname.indexOf('.')).replaceAll('(-)([A-Za-z0-9])', { Object[] it -> it[2].toUpperCase() } ) else res=fname; return res")