【发布时间】:2014-02-02 16:33:45
【问题描述】:
在php中我可以写
preg_match('/a(.*)b(.*)c/', '00a123b456c00', $result);
在 $result 中,我将在 $result[1] 中得到 123,在 $result[2] 中得到 456,在 $result[0] 中得到 a123b456c。如何捕获与正则表达式匹配的文本以及它在 Emacs Lisp 中的不同部分?
【问题讨论】:
在php中我可以写
preg_match('/a(.*)b(.*)c/', '00a123b456c00', $result);
在 $result 中,我将在 $result[1] 中得到 123,在 $result[2] 中得到 456,在 $result[0] 中得到 a123b456c。如何捕获与正则表达式匹配的文本以及它在 Emacs Lisp 中的不同部分?
【问题讨论】:
像这样:
(let ((str "00a123b456c00"))
(when (string-match "a\\(.*\\)b\\(.*\\)c" str)
(list (match-string 0 str)
(match-string 1 str)
(match-string 2 str))))
【讨论】: