I have a function that tries to extract the year from date strings stored in an alist below:
(setq entry
'(("date" . "1998/03")
("origdate" . "1930")))
(defun extract-year (date)
(let ((string (cdr (assoc (symbol-name 'date) entry))))
(progn
(string-match
"\\([0-9]\\{4\\}\\)[/-年\\.]?\\([0-9]+\\)?[/-月\\.]?\\([0-9]+\\)?[/-日\\.]?"
string)
(match-string 1 string))))
I would like to call, for example, (extract-year date)
to get "1998"
and (extract-year origdate)
to get "1930"
.
(extract-year "date")
. – xuchunyang Nov 8 '20 at 11:53(assoc (symbol-name 'date) entry)
should simply be(assoc date entry)
? – Sati Nov 8 '20 at 13:05(defun extract-year (date-string) ...)
which can be used as(extract-year "2020/11/09") => 2020
– xuchunyang Nov 8 '20 at 16:51