Advertisement
mark-naylor-1701

Regular Expression Matches

Feb 5th, 2022 (edited)
2,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.44 KB | None | 0 0
  1. (defun regex-matches (re s &optional start)
  2.   "Given a regular expression and a string, return a sequence of
  3. matches, including groups, if any."
  4.   (cl-labels
  5.       ((regex-matches
  6.         (acc index)
  7.         (let ((this-match (match-string index s)))
  8.           (cond
  9.            (this-match (regex-matches (cons this-match acc) (1+ index)))
  10.            (t (reverse acc))))))
  11.  
  12.     (when (string-match re s start)
  13.       (regex-matches '() 0))))
Tags: elisp regexp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement