(defun ere (re)
"Convert an ERE-style regexp RE to an Emacs-style regexp."
(let ((pos 0)
(last 0)
(chunks '()))
(while (string-match "\\\\.\\|[{}()|]" re pos)
(let ((beg (match-beginning 0))
(end (match-end 0)))
(when (subregexp-context-p re beg)
(cond
;; A normal paren: add a backslash.
((= (1+ beg) end)
(push (substring re last beg) chunks) (setq last beg)
(push "\\" chunks))
;; A grouping paren: skip the backslash.
((memq (aref re (1+ beg)) '(?\( ?\) ?\{ ?\} ?\|))
(push (substring re last beg) chunks)
(setq last (1+ beg)))))
(setq pos end)))
(mapconcat #'identity (nreverse (cons (substring re last) chunks)) "")))