/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. (def re-match-pat (pat str)
  4. (ac-niltree ($.regexp-match ($.pregexp pat) str)))
  5. (def re-match (pat str)
  6. (only.cdr (re-match-pat pat str)))
  7. (def re-split (delim str)
  8. ($.regexp-split delim str))
  9. (def re-replace (pat text replacement)
  10. ($.regexp-replace* ($.pregexp pat) text replacement))
  11. ; TODO why did I want this in addition to re-split again?
  12. (def matchsplit (pat str)
  13. (let pos (posmatch pat str)
  14. (if pos
  15. (list (cut str 0 pos) (cut str (+ 1 pos)))
  16. (list str))))