我尝试在 emacs lisp 中使用正则表达式分支,令我惊讶的是,它看起来只支持基本正则表达式,但文档没有明确提及。我想知道我是否做错了什么。
下面是我的测试,有证据表明 emacs lisp 不支持扩展正则表达式,并通过 grep 检查来证明我的正则表达式实际上可以在 emacs 之外工作。
;; Using extended regular expressions
(string-match "(two|three)" "one, two, three, four, five") ;; result: NO match
;; Using basic regular expressions (no branches)
(string-match "two" "one, two, three, four, five") ;; result: match
echo "one, two, three, four, five" | grep -E "(two|three)" # result: match
就像我帖子的评论中提到的那样,答案在手册中:emacs lisp 支持扩展正则表达式吗?