CL-PPCRE:REGISTER-GROUPS-BIND将字符串与正则表达式匹配,如果匹配,则将正则表达式中的寄存器组绑定到变量。如果字符串不匹配,NIL则返回。
(defun parse-date-string (date-string) (cl-ppcre:register-groups-bind (year month day) ("(\\d{4})-(\\d{2})-(\\d{2})" date-string) (list year month day))) (parse-date-string "2016-07-23") ;=> ("2016" "07" "23") (parse-date-string "foobar") ;=> NIL (parse-date-string "2016-7-23") ;=> NIL