I have a problem where I fail to get a match-string after a string-match. 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?
The failing function:
(defun small-test ()
(string-match "\\([0-9]+\\)-v\\([0-9]+\\).txt" "2011-v9.txt")
(message (match-string 1))
)
From C-h f match-string, I suggest that you read the bottom line:
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With