Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 Emacs Lisp 还很陌生,并且仍在学习如何做一些基础知识。
我有一些文本[123],我想提取数字123。我做了一些不同的尝试,但我似乎仍然无法可靠地捕捉到这个数字。我得到的最接近的是提取字符]。
[123]
123
]
谁能指出我的方向?我最大的困难是了解如何在使用后捕获数字search-forwards并search-backwards捕获括号的点位置。
search-forwards
search-backwards
提前致谢!
尝试
(when (re-search-forward "\\[\\([0-9]+\\)\\]" nil t) (string-to-number (match-string 1)))
或者,当点已经在数字的顶部时,thing-at-point可能更方便:
thing-at-point
(string-to-number (thing-at-point 'sexp))