I am trying to write a small function where I extract two sub-strings from a cite-key, e.g.
(defun citekey-get-author-and-year () "Get the _author_ and _YEAR_ from a cite:authorYEARtitle key." (interactive) ; allow this to be user-callable (let ((regexp ":\(.*\)\([0-9]*\)[a-z]") ; the regex to parse author year (citekey (buffer-substring (line-beginning-position) (line-end-position))))) (when (string-match 'regexp 'citekey) (setq author (match-string 1 string) year (match-string 2 string))) )
The above code gives me a "Wrong type argument: stringp, regexp" error. I came up with it after reading the manual. If I do it without the
'regexp 'citekey line, I get the error "Symbols value as a variable is void: regexp".
Based on the error description, the function doesn't know what regexp and citekey are, but why?
I tried debugging it with
debug-on-entry, as described here. Unfortunately I did not really see or understand where the error is.
My code is inspired by the
string-match documentation, and it confuses me very much that it doesn't work.
Demos #+BEGIN_SRC elisp (let ((string "Today is <2018-11-07>.")) (when (string-match "<\\([-0-9]+\\)>" string) (match-string 1 string))) #+END_SRC
When searching online for the error code, there are a bunch of results, but as the error seems very generic I didn't find anything that solved my problem.
I believe that the mistake is really basic and obvious, it is just that my understanding of elisp is lacking, as this is the first function I write.