Emacs lisp: get sub-matches from a regexp match
elisp, emacs
Solution
(save-match-data ; is usually a good idea
(and (string-match "\\`\\([^@]+\\)@\\([^@]+\\)\\'" email)
(setq user (match-string 1 email)
domain (match-string 2 email) ) ))
The GNU Emacs Lisp Reference Manual is your friend. See also http://emacswiki.org/emacs/ElispCookbook
Problem
I have a string variable somewhere in elisp code, and want to extract some parts of it into other variables using a regular expression with groupings. That's something that you can write in 1-2 lines in any language: `my ($user, $domain) = $email =~ m/^(.+)@(.+)$/;` How do I write the same in elisp?