How to capture parts of a string in Emacs Lisp?

In php I can write

preg_match('/a(.*)b(.*)c/', '00a123b456c00', $result);

and in $ result I will get 123in $result[1], 456in $result[2]and a123b456cin $result[0]. How to take the text matched with the regular expression and its different parts, as in Emacs Lisp?

+4
source share
1 answer

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))))
+4
source

Source: https://habr.com/ru/post/1524951/


All Articles