Match-string in elisp does not return string matched by string match

I have a problem where I cannot get a match string after a string. I think the string match works, at least it returns non nil, but I get an error when I try to get the match string. How should I do it?

Unsuccessful function:

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

From the line of correspondence Ch f, I suggest you read the bottom line:

(NUM matching string and optional STRING)

, . NUM , . , NUMth , , NUM . . STRING , `string-match 'on STRING.

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

+1

Source: https://habr.com/ru/post/1795692/


All Articles