How do I capture parts of a string in Emacs Lisp?
elisp, emacs, regex
Solution
Like this:
(let ((str "00a123b456c00"))
(when (string-match "a\\(.*\\)b\\(.*\\)c" str)
(list (match-string 0 str)
(match-string 1 str)
(match-string 2 str))))
Problem
In php I can write ``` preg_match('/a(.*)b(.*)c/', '00a123b456c00', $result); ``` and in $result I will get `123` in `$result[1]`, `456` in `$result[2]` and `a123b456c` in `$result[0]`. How do I capture text matched with regex and it's different parts like that in Emacs Lisp?