PageRenderTime 18ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/re.arc

http://github.com/alimoeeny/arc
Unknown | 21 lines | 16 code | 5 blank | 0 comment | 0 complexity | fa8a4e32a236e19a30aca4921f9174d5 MD5 | raw file
 1; re started by Mark Huetsch
 2; some of this code is lifted (with slight modifications) from Andrew Wilson's site (http://awwx.ws/re2.arc)
 3
 4(def re-match-pat (pat str)
 5  (ac-niltree ($.regexp-match ($.pregexp pat) str)))
 6
 7(def re-match (pat str)
 8  (only.cdr (re-match-pat pat str)))
 9
10(def re-split (delim str)
11  ($.regexp-split delim str))
12
13(def re-replace (pat text replacement)
14  ($.regexp-replace* ($.pregexp pat) text replacement))
15
16; TODO why did I want this in addition to re-split again?
17(def matchsplit (pat str)
18  (let pos (posmatch pat str)
19    (if pos
20	    (list (cut str 0 pos) (cut str (+ 1 pos)))
21	    (list str))))