The (potluck regexc) module provides a macro for throwing a string at a sequence of regular expressions, executing an associated body when a match is found. Attached are three files: * regexc.scm: the source code * regexc.texi: documentation * regexc.test: test code Regexp Utilities ---------------- -- Scheme Procedure: regexp-case str case ... [else body] Match the string STR against each CASE in turn. Each CASE is of the form ((pat VAR1 VAR2 ...) body) where pat is a regular expression string literal, VAR1 ... are bound to the ordered list of matched subexpressions, and BODY is a sequence of expressions. If no match is found and the optional ELSE case exists, the associated body is executed, otherwise an error is signaled. The following example matches a string aginst either a simple variable name, or a simple variable name with an array reference, and returns a list with the variable name and the string index, or '"1"'. If no match is found, '#f' is returned. (define str "foo") (regexp-case str (("^([a-z]+)\\(([0-9]+)\\)$" var idx) (list var idx)) (("^([a-z]+)$" var) (list var "1")) (else #f)) ==> ("foo" "1") -- Scheme Procedure: make-string-matcher (str ...) case ... [else body] This is similar to 'regexp-case' but generates a procedure '(lambda (str ...) ...)' that matches its string argument STR againt each CASE in turn. (define my-matcher (make-string-matcher (str a b c) (("^([a-z]+)\\(([0-9]+)\\)$" var idx) (list var idx)) (("^([a-z]+)$" var) (list var "1")) (else #f))