我在 elisp 代码的某处有一个字符串变量,并且想使用带有分组的正则表达式将它的某些部分提取到其他变量中。这是你可以用任何语言用 1-2 行写的东西:my ($user, $domain) = $email =~ m/^(.+)@(.+)$/;
我如何在 elisp 中编写相同的内容?
最佳答案
(save-match-data ; is usually a good idea
(and (string-match "\\`\\([^@]+\\)@\\([^@]+\\)\\'" email)
(setq user (match-string 1 email)
domain (match-string 2 email) ) ))
GNU Emacs Lisp Reference Manual是你的 friend 。另见 http://emacswiki.org/emacs/ElispCookbook
关于Emacs 口齿不清 : get sub-matches from a regexp match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16243159/