给定一个文件名,我想将文件扩展名替换为“.org”
我决定使用 replace-regexp-in-string
功能:
(replace-regexp-in-string "\\(.*\\)\..*$" "\\1.org" "file.conserv.module")
输出:
"file.conserv.modul.org"
我想,它会像在 Perl 程序中一样返回“file.conserv.org”:
my $str = 'file.conserv.module';
$str =~ s/(.*)\..*$/$1.org/;
print $str;
我怎样才能得到“file.conserv.org”?
最佳答案
这可以在没有任何正则表达式的情况下执行您想要的操作:
(concat (file-name-sans-extension "file.conserv.module") ".org")
如果您也想删除路径:
(concat (file-name-base "file.conserv.module") ".org")
关于regex - Emacs:替换文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25204386/