common-lisp Binding register groups with CL-PPCRE


Example

CL-PPCRE:REGISTER-GROUPS-BIND will match a string against a regular expression, and if it matches, bind register groups in the regex to variables. If the string does not match, NIL is returned.

(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