【问题标题】:How do I capture parts of a string in Emacs Lisp?如何在 Emacs Lisp 中捕获部分字符串?
【发布时间】: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 中的不同部分?

【问题讨论】:

    标签: regex emacs elisp


    【解决方案1】:

    像这样:

    (let ((str "00a123b456c00"))
      (when (string-match "a\\(.*\\)b\\(.*\\)c" str)
        (list (match-string 0 str)
              (match-string 1 str)
              (match-string 2 str))))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多