(bind-func regex_matches
(lambda (regex:i8* str:i8* maxnum:i64)
(let ((slen:i64 (strlen str))
(results:i8** (salloc maxnum))
(resdata:i8* (salloc (* slen maxnum)))
(result:String* null) (i:i64 0) (num 0))
(dotimes (i maxnum) (pset! results i (pref-ptr resdata (* i slen))))
(set! num (rmatches regex str results maxnum))
(if (> num 0)
(map (lambda (i:i64) (Str (pref results i)))
(range 0 num))
null))))