加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式 – 如何在Emacs Lisp中捕获字符串的一部分?

发布时间:2020-12-14 05:58:33 所属栏目:百科 来源:网络整理
导读:在 PHP我可以写 preg_match('/a(.*)b(.*)c/','00a123b456c00',$result); 在$result中,$result [1]中得到123,$result [2]中得到456,$result [0]中得到a123b456c.如何捕获与正则表达式匹配的文本,以及它与Emacs Lisp中的不同部分? 解决方法 像这样: (let ((s
在 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))))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读