MacroPackage: exclToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 8.2
Moderately revised from 8.1.
8.1 version

re-case

Arguments: string &rest clauses

string must be an expression that evaluates to a string. The clauses are then examined one by one, checking whether it matches string or not. clauses must be one of the following forms:

If no clause match, nil is returned.

See also re-let and re-lambda.

Example

cl-user(4): (setq f
	      (re-lambda "([^ ]+) ([^ ]+) ([^ ]+)"
		  ((foo 1) (bar 2) (baz 3))
		(list foo bar baz)))
#<Interpreted Function (unnamed) @ #x71ed7892>
cl-user(5): (funcall f "foo the bar")
("foo" "the" "bar")
cl-user(6): (re-let "([^ ]+) ([^ ]+) ([^ ]+)"
		"foo the bar"
		((foo 1) (bar 2) (baz 3))
	      (list foo bar baz))
("foo" "the" "bar")
cl-user(7): 


cl-user(9): (re-case "foo the barmy"
	      ("foo a (.*)" ((it 1)) (list it))
	      ("foo the (.*)" ((it 1)) (list it))
	      (t :no-match))
("barmy")
cl-user(10): (re-case "foo a barmy"
	      ("foo a (.*)" ((it 1)) (list it))
	      ("foo the (.*)" ((it 1)) (list it))
	      (t :no-match))
("barmy")
cl-user(11): (re-case "foo xx barmy"
	      ("foo a (.*)" ((it 1)) (list it))
	      ("foo the (.*)" ((it 1)) (list it))
	      (t :no-match))
:no-match
cl-user(12): 

cl-user(30): (labels ((parse-date (input)
                        (re-case input
                          ("^(\\d{4})([-/])(\\d{1,2})\\2(\\d{1,2})$"
                           ((year 1) (month 3) (day 4))
                           (mapcar #'read-from-string (list year month day)))
                          ("^(\\d{1,2})([-/])(\\d{1,2})\\2(\\d{4})$"
                           ((year 4) (month 1) (day 3))
                           (mapcar #'read-from-string (list year month day)))
                          ("^(\\d{2})([-/])(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\2(\\d{4})$"
                           ((year 4) (month 3) (day 1))
                           (list
                            (read-from-string year)
                            (cdr
                             (assoc month
                                    '(("Jan" . 1) ("Feb" . 2) ("Mar" . 3)
                                      ("Apr" . 4) ("May" . 5) ("Jun" . 6)
                                      ("Jul" . 7) ("Aug" . 8) ("Sep" . 9)
                                      ("Oct" . 10) ("Nov" . 11) ("Dec" . 12))
                                    :test #'equal))
                            (read-from-string day))))))
               (list (parse-date "2004/7/21")
                     (parse-date "7-21-2004")
                     (parse-date "21-Jul-2004")))
((2004 7 21) (2004 7 21) (2004 7 21))
cl-user(31): 

The symbol naming this operator is also exported from the regexp package.

See The new regexp2 module in regexp.htm for further information on this macro and the regexp2 module.


Copyright (c) 1998-2016, Franz Inc. Oakland, CA., USA. All rights reserved.
This page has had moderate revisions compared to the 8.1 page.
Created 2016.6.21.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 8.2
Moderately revised from 8.1.
8.1 version