Skip to content

Instantly share code, notes, and snippets.

@shrdlu68
Last active November 27, 2018 04:46
Show Gist options
  • Save shrdlu68/d49c632576b69c524e9e47e7c9df4d77 to your computer and use it in GitHub Desktop.
Save shrdlu68/d49c632576b69c524e9e47e7c9df4d77 to your computer and use it in GitHub Desktop.
(ql:quickload :cl-ppcre)
(defun decompress (in)
(multiple-value-bind (string matchp)
(cl-ppcre:regex-replace "([0-9]+)\\[([^][]*)\\]"
in
(lambda (match reg1 reg2)
(declare (ignorable match))
(format nil "~v@{~A~:*~}" (parse-integer reg1) reg2))
:simple-calls t
:preserve-case t)
(if matchp
(decompress string)
string)))
;; (decompress "3[abc]4[ab]c") => "abcabcabcababababc"
;; (decompress "2[3[a]b]") => "aaabaaab"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment