Created
August 22, 2019 20:11
-
-
Save drewc/ea277d14144ad0691d10d5d7f18a1f92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(user)> (def (pregexp-match* re str (start 0) (end (string-length str))) | |
(def (%m start end) | |
(if (= start end) | |
'() (let ((first (pregexp-match-positions re str start end))) | |
(if (not first) '() | |
(cons (cadr first) (%m (+ 1 start) end)))))) | |
(let ((idxs (delete-duplicates (%m start end) equal?))) | |
(map (lambda (idx) (substring str (car idx) (cdr idx))) idxs))) | |
#!void | |
(user)> (pregexp-match* "(a)" "aa ab ac") | |
("a" "a" "a" "a") |
Author
drewc
commented
Aug 22, 2019
•
(user)>
(def (pregexp-match* re str (start 0) (end (string-length str)))
(def (%m start end)
(if (= start end)
'()
(let ((first (pregexp-match-positions re str start end)))
(if (not first) '()
(cons (if (null? (cddr first))
(cadr first) (cdr first)) (%m (+ 1 start) end))))))
(let ((idxs (delete-duplicates (flatten1 (%m start end)) equal?)))
(map (lambda (idx) (substring str (car idx) (cdr idx))) idxs) ))
#!void
(user)> (pregexp-match* "(a)(a)" "aa aa aa")
("a" "a" "a" "a" "a" "a")
(user)>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment