common-lisp Using with pattern matching to bind captured groups


Example

The pattern matching library trivia provides a system trivia.ppcre that allows captured groups to be bound through pattern matching

(trivia:match "John Doe"
  ((trivia.ppcre:ppcre "(.*)\\W+(.*)" first-name last-name)
   (list :first-name first-name :last-name last-name)))

;; => (:FIRST-NAME "John" :LAST-NAME "Doe")
  • Note: the library Optima provides a similar facility in the system optima.ppcre