gpt4 book ai didi

regex - elisp 中的匹配字符串不返回与字符串匹配匹配的字符串

转载 作者:行者123 更新时间:2023-12-04 22:51:17 25 4
gpt4 key购买 nike

我有一个问题,在字符串匹配后我无法获得匹配字符串。我认为字符串匹配有效,至少它返回非零,但是当我尝试获取匹配字符串时出现错误。我该怎么做?

失败的功能:

(defun small-test ()
(string-match "\\([0-9]+\\)-v\\([0-9]+\\).txt" "2011-v9.txt")
(message (match-string 1))
)

最佳答案

从 C-h f match-string,我建议你阅读底线:

(match-string NUM &optional STRING)

Return string of text matched by last search. NUM specifies which parenthesized expression in the last regexp. Value is nil if NUMth pair didn't match, or there were less than NUM pairs. Zero means the entire text matched by the whole regexp or whole string. STRING should be given if the last search was by `string-match' on STRING.

关于regex - elisp 中的匹配字符串不返回与字符串匹配匹配的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5165429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com