; regex ; for doing regex matches (func match? :bool (pattern :string text :string) (.search pattern text)) (func .match-one :bool (left right) (in? left (list "" "." right))) (func .match-? :bool (pattern text) (or (and (.match-one (first-char pattern) (first-char text)) (.match-inner (rest-char (rest-char pattern)) (rest-char text))) (.match-inner (rest-char (rest-char pattern)) text))) (func .match-* (pattern text) (or (and (.match-one (first-char pattern) (first-char text)) (.match-inner pattern (rest-char text))) (.match-inner (rest-char (rest-char pattern)) text))) (func .match-inner (pattern text) (branch ((eq? "" pattern) #true) ((and (eq? "$" pattern) (eq? "" text)) #true) ((eq? "" text) #false) ((and (>= (length pattern) 2) (eq? "?" (first-char (rest-char pattern)))) (.match-? pattern text)) ((and (>= (length pattern) 2) (eq? "*" (first-char (rest-char pattern)))) (.match-* pattern text)) (#true (and (.match-one (first-char pattern) (first-char text)) (.match-inner (rest-char pattern) (rest-char text)))))) (func .search (pattern text) (if (eq? "^" (first-char pattern)) (.match-inner (rest-char pattern) text) ;(.match-inner (concat ".*" pattern) text))) ; this is elegant but requires going through the entire string (block (def seed (list)) (for-count (length text) (redef seed (append seed idx))) (not (empty? (drop-while seed (not (.match-inner pattern (join (slice (split text) _item_) "")))))))))