* Imported original elk 3.0 tree.
git-svn-id: svn://svn.zoy.org/elk/trunk@1 55e467fa-43c5-0310-a8a2-de718669efc6
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
;;; -*-Scheme-*-
|
||||
;;;
|
||||
;;; Demonstrate the regular expression primitives.
|
||||
|
||||
(require 'regexp)
|
||||
|
||||
;; Returns a list of substrings of string `str' that match the
|
||||
;; pattern `pat'
|
||||
|
||||
(define (matches str pat)
|
||||
(let loop ((r (make-regexp pat '(extended))) (result '()) (from 0))
|
||||
(let ((m (regexp-exec r str from)))
|
||||
(if (regexp-match? m)
|
||||
(loop r (cons (substring str (+ from (regexp-match-start m 0))
|
||||
(+ from (regexp-match-end m 0)))
|
||||
result)
|
||||
(+ from (regexp-match-end m 0)))
|
||||
(reverse result)))))
|
||||
|
||||
(require 'siteinfo)
|
||||
|
||||
(cond
|
||||
((feature? ':regular-expressions)
|
||||
(print (matches "Hello, world!" "[a-zA-z]+"))
|
||||
(print (matches "Hello, world!" ".")))
|
||||
(else
|
||||
(format #t "Regular expressions not supported by ~a-~a~%"
|
||||
site-machine site-os)))
|
||||
Reference in New Issue
Block a user