Skip to content

Instantly share code, notes, and snippets.

@legumbre
Created August 15, 2011 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save legumbre/1148156 to your computer and use it in GitHub Desktop.
Save legumbre/1148156 to your computer and use it in GitHub Desktop.
longest common suffix of two strings
;; awful hack, get the common suffix from two strings using regexp-quote
(let* ((a "foo/bar")
(b "baz/bar")
(ro (regexp-opt (list a b))))
(string-match "\\\\)\\(.*?\\)\\\\)$" ro)
(match-string 1 ro))
;; "/bar"
;; what trickery be this?!
;; (regexp-opt '("foooooooobaz" "barrrrrrrbaz")) ;; "\\(?:\\(?:barrrrrrr\\|foooooooo\\)baz\\)"
;; so we match the last \\)baz\\)$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment