common-lisp                
            正規表現
        
        
            
    サーチ…
パターンマッチングを使用してキャプチャされたグループをバインドする
パターンマッチングライブラリtriviaは、 trivia.ppcreされたグループをパターンマッチングによってバインドできるシステムtrivia.ppcreを提供します
(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")
- 注:ライブラリOptimaはシステムoptima.ppcre同様の機能を提供します
CL-PPCREによるレジスタグループのバインド
 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
Modified text is an extract of the original Stack Overflow Documentation
        ライセンスを受けた CC BY-SA 3.0
        所属していない Stack Overflow