Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[deprecated, use visual-regexp/visual-regexp-steroids instead] A Python regexp/replace command for Emacs with interactive visual feedback

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 screenshots
Octocat-spinner-32 pyregexp.el


pyregexp is deprecated in favor of visual-regexp (Emacs style visual regexps) and visual-regexp-steroids (Python backend).

pyregexp is a command for emacs which enables you to use Python regular expressions and either a Python string or a Python expression for doing replacements.

While constructing the regexp in the minibuffer, you get live visual feedback for the matches, including group matches:

entering regexp

While constructing the replacement in the minibuffer, you get live visual feedback for the replacements:

entering replacement

It can be used to replace all matches in one go (like replace-regexp), or a decision can be made on each match (like query-replace-regexp). Incremental search using Python regular expressions is also supported, as a drop-in replacement for isearch-forward-regexp/isearch-backward-regexp.

Besides doing replacements in regular buffers, one of the most interesting uses of pyregexp is renaming a bunch of files directly in a dired buffer. See Example 4.


Put pyregexp.el and into the same directory.

If you are using Emacs 24, you can get pyregexp from melpa with the package manager.

You need a Python interpreter. Add the following code to your init file. Of course you can select your own key bindings.

(add-to-list 'load-path "folder-in-which-pyregexp-files-are-in/") ;; if the files are not already in the load path
(require 'pyregexp)
(define-key global-map (kbd "C-c r") 'pyregexp-replace)
(define-key global-map (kbd "C-c q") 'pyregexp-query-replace)
;; to use pyregexp isearch instead of the built-in regexp isearch, also include the following lines:
(define-key esc-map (kbd "C-r") 'pyregexp-isearch-backward)
(define-key esc-map (kbd "C-s") 'pyregexp-isearch-forward)

To customize, use M-x customize-group [RET] pyregexp. You can specify how the Python interpreter is invoked by modifying the pyregexp-command-prefix variable. The default is python /path/to/


Example 1

Example 1

Example 2

Zero-width matches are indicated by a pipe. When replacing using a Python expression, the counter variable i is available. Example 2

Example 3

Example 3

Example 4

pyregexp can be combined with wdired-change-to-wdired-mode to rename files directly in a dired buffer, using regular expressions with a live preview: Example 3

Something went wrong with that request. Please try again.