Previous: Maurader's
Previous: Maurader's
gedit Plugin
gedit Plugin
Next: CellRename
Next: CellRename

gedit regular expression plugin

(from a blog post I wrote in 2008. this plugin became popular, especially after it was linked to from the official gedit website)

A friend told me that gedit was missing a plugin for regular expressions. I use gedit occasionally, and so I made this plugin. Because it uses Python's full regular expression support, you can use backreferences, making it possible to do some interesting search and replace operations.

For example, in the screenshot above, the complicated-looking expresion is just saying to look for anything in the format "aaa.bbb" and replace it with "". The ( ) parens in the search string designate a "capture group", and the \1 in the replace string will be filled in with the first "capture group". You can also use \0 to refer to the entire matched string.

Updated version

Adam Brandizzi has forked the code and created an improved version compatible with gedit 3.

I recommend that you use his version at Bitbucket here.

Original 2008 version

To install, download from here and place the files in ~/.gnome2/gedit/plugins/. Then open gedit, choose Preferences from the Edit menu. On the plugins tab, you should see Regular Expression Replace in the list. Check to enable. Now, you should have a "Regular Expression" item in the Search menu.

This plugin is based on extensão para o gEdit by Rafael Silva. I fixed a couple bugs, cleaned up the interface, moved the menuitem to the Search menu, added backreferences support, added replace all, and added an option for case-sensitivity. Also, the search mode is now multiline, and so ^ matches the start of a line.

On 10:41:00 PM April 13, 2008, eplawless wrote:

Thanks for this; really excellent work.

On 09:32:00 PM April 22, 2008, Sandy wrote:

Thank you, I was looking for just this sort of thing!

On 08:39:00 PM May 08, 2008, Ben wrote:

Thanks, it works perfectly.

Question: Is it possible to use Ctrl-H shortcut? Or add a shortcut for it, at least.

On 06:16:00 PM May 21, 2008, Rafael wrote:

Hey man, very nice to see my contribution could be extended!

I'll test later!

Thank you!

On 02:27:00 PM September 23, 2008, mork wrote:

thank you! good work!

On 12:27:00 PM December 03, 2008, Rafael wrote:

Hey Ben,
I'm commenting just to thank you for the work. It's being useful.


On 07:27:00 AM April 02, 2009, Waldir wrote:

Thanks a lot for the excellent plugin. However it would be even better if it didn't disable the replace buttons if there's no text in the replace field. Sometimes we need to just remove some parts of a text, not replace them with something else. Can you do this?

On 03:10:30 AM June 01, 2009, Faceleg wrote:

Thanks for this!

I agreed with Waldir, being able to replace text with nothing (delete) is very useful.

On 12:22:20 AM June 02, 2009, Andrew wrote:

Thanks for this, but my first use of it found a bug. I want to remove the first two leading spaces, so I search for '^ '

It looks like the '^' is not bound to the start of the current line, it's bound to the point where the search begins. Being cautious, I used 'find' a few times before doing the replace all. It steps through multiple matches on the same line.

My wishlist:

1. Fix the above
2. Add a hotkey to bring up the dialog
3. Add a replace and search again button with keyboard shortcut.

It's nearly there.

I've been using nedit, which is not bad, except that it doesn't understand the gnome virtual file system, which would be much more convenient sometimes.

On 08:32:19 PM July 21, 2009, rob wrote:

Nice, thanks! It would be nice to have a keyboard shortcut or a 'highlight all' option.

On 02:53:04 AM July 28, 2009, beli wrote:

Thanks, very useful!

On 02:54:40 AM July 28, 2009, beli wrote:

Would it be possible to replace text in a highlighted (selected with the mouse cursor) region?

On 11:38:58 AM August 02, 2009, brian.j.bowers wrote:

Yeah, I agree. Can we add a checkbox option for "Search/Replace Within Selected Text Only"?

On 03:05:39 PM December 04, 2009, sergey892 wrote:

Thanks for the great plugin! Regular expressions really make gedit useful!

On 08:44:57 PM February 16, 2010, njcar wrote:

Hey Ben,

Thanks for the awesome plugin. Hope I have the skills to write these sorts of things one day.


On 08:12:14 AM March 09, 2010, tiggsy wrote:

Lovely! Now, why don't they just include this with the regular plugins, i wonder?

On 12:58:21 AM April 15, 2010, ed wrote:

Easy to install and use.
Many thanks!

On 03:22:21 AM May 01, 2010, heman wrote:


On 02:23:15 PM May 02, 2010, LiraNuna wrote:

I would say, extend the original search and replace interface and add a 'Regular expression' option - best of both world.

On 11:38:45 PM May 19, 2010, wrote:

very useful plugin, thanks

On 07:57:51 AM May 20, 2010, Maxo wrote:

I'd like to echo what LiraNuna said. It would be great if this extended the regular Search and Replace window.
Otherwise, very useful.

On 01:55:32 PM May 27, 2010, Noel wrote:

Great work!! It would be nice to have an option to toggle between single-line and multi-line mode.

On 07:49:53 AM June 01, 2010, johann.fot wrote:


On 01:09:29 AM June 17, 2010, PhoneixS wrote:

Thanks for the plugin. Can you make it translatable, if you like, I can translate it's texts into spanish.

On 02:59:17 PM August 22, 2010, Yva wrote:

Very nice work!

Small bug though: when there is 2 successive matches the second one isn't caught.
Example: when using "<.+?>" on "<b>this is <a></a></b>a test test" the < /b> isn't caught.

On 07:02:23 AM September 04, 2010, Thomas Käfer wrote:

Thanks for the great plugin!

What im missing:
-) Shortcut or merge with standard replace strg+h
-) Dont disable replace buttons when replace field is empty

On 07:56:50 AM September 22, 2010, ... wrote:

For those who want to replace something for nothing (the empty string), if we open the file "" and change the line
if len(search_text) > 0 and len(replace_text) > 0:
if len(search_text) > 0:# and len(replace_text) > 0:
and save, the program will not disable the replace all button. (but I'm not sure if it will break it in anyway - I hope not).

On 02:26:00 AM October 20, 2010, Gavin wrote:

nice plugin. Im having a problem with replacing, unless I'm doing something wrong. Replace with '\n' inserts literal \n instead of LF.

I'm trying to add text at the beginning of each line:

match: '\n'
replace: '\n2010-09-17,'

the match works but the replace not.

On 10:01:56 AM October 20, 2010, Waldir wrote:

Gavin, I too find that annoying, but you can use a trick to workaround that: just enclose the \n in the search field as (\n), and use \1 (or whatever numbered reference it is) in the replace field.

Granted, this is not a complete solution, since not always you'll have newlines in the search field, but as I said, it's a workaround :)

Btw, thanks anonymous (↑↑) for the empty string replace trick! However, I think I don't recall doing it, and nevertheless the replace button doesn't get deactivated when the replace field is empty (I can't remember when it stopped doing that). Can anyone confirm this is the default behavior without applying anonymous' hack? Maybe something changed in gedit itself.

On 02:10:30 AM December 05, 2010, pmorton wrote:

This is really useful. I'm having trouble with changing case though. \L and \U don't work on backreferences in the replace field to change the case to upper. Does anyone know how to change case?

On 11:30:20 AM January 01, 2011, Richard wrote:

seems to work well, thanks a lot,
gedit really needed some regex support

On 10:07:59 AM January 06, 2011, ihoru wrote:

Thank u!!

On 01:51:32 PM January 30, 2011, MPS wrote:

Really, really great!! Exactly what I was looking for. Many thanks

On 05:54:06 PM February 11, 2011, Donald wrote:

Thanks. This is great!!

On 11:41:13 AM March 31, 2011, Ironarjen wrote:

Sorry, does not work at all. Regex Search and replace appears in the Plugin list but checking it does not change the search box

On 08:30:16 AM April 01, 2011, Waldir wrote:

@Ironarjen it does work, but unfortunately it's not integrated into the main search/replcace dialogs. You have to use the menu Search > Regular expression (since there isn't a keyboard shortcut either).

On 03:05:42 AM April 07, 2011, Nik wrote:

Amazing thank you very much for this time saving plugin
Very easy to use

On 06:56:19 AM April 16, 2011, quinn wrote:

Thank you! Your plugin is wonderful.

On 06:13:24 AM April 22, 2011, François Michonneau wrote:

It doesn't seem to work in gedit 3 (doesn't show up in the menu). I put the plugin in ~/.local/share/gedit/plugins. Any hints on how to solve this?

On 06:57:55 AM May 11, 2011, Paul wrote:

I'm using the Windows version of gEdit 2.30.1 (latest available!) and when I select the plugin in preferences it just greys out. Any ideas?

That's actually better than most plugins I've tried which just crash gEdit!

On 07:53:03 AM May 11, 2011, Paul wrote:

Just to update, installing glade 3.6.7 (with GTK+) - all 17M - allowed me to select the check box and the plugin seems to function.

It would be nice to know which bits I really need and where they need to be located in Windows or the gEdit structure?

On 11:52:41 PM May 18, 2011, Bowser wrote:

Great plugin, does what it says. Thanks for posting!

On 08:18:12 AM July 13, 2011, kyogre wrote:

Totally awesome !!! Thank u man, a lot!

On 03:02:14 AM July 25, 2011, typedef uchar_t pluto; wrote:

Thanks very much.. Very useful and most needed plugin.

On 06:53:30 AM August 05, 2011, Michael wrote:


There is no way to make the plugin work in Gnome 3. Plugins for Gnome 2 are built in Gtk+2 but plugins for Gnome 3 are built in Gtk+3. I've run into this problem with other plugins I use that to run in Gnome 3 they require a complete recoding so until then we are out of luck, which is unfortunate because I really love this plugin.


Do you have any plans to update the plugin to gnome 3 or should those of use on gnome 3 look for another solution?

On 11:17:04 AM August 09, 2011, David Brault wrote:

This comment has been removed by the author.

On 11:17:26 AM August 09, 2011, David Brault wrote:

Yay! Thank you. Got it working on my machine now.

On 01:45:15 PM August 26, 2011, Stephen Bussard wrote:


On 02:12:49 AM October 29, 2011, Nemo wrote:

How do I get this work on gedit/gnome 3? I placed it under .local/share/gedit/plugins but it doesn't work, and is total crap

On 11:55:48 PM October 30, 2011, Etienne Lawlor wrote:

I am also having trouble installing this plugin with gedit version 3.2.1. Has anyone been able to install this plugin successfully?

On 02:48:48 PM November 19, 2011, KeyNeom wrote:

What are the dependencies for your plugin? I'm running Arch-Linux with gnome3. I used the gnome3 version of the plugin I found at the gnome3 gedit plugins page but when I click "Regular Expression..." from the Search menu in gedit I get a blank frame that pops up. I haven't seen this happen with anything else so I figure it must be the dependencies you are using but any other suggestions are welcome. Thanks for your work!

On 03:46:05 AM January 10, 2012, webe wrote:

hi ben.fisher,

thanks alot.

Works great on Ubuntu 10.04.2 LTS.
Great help for editing srt-files.


PS. minor request: remember regex

On 09:16:00 AM January 13, 2012, edek wrote:

Path for gedit plugins has changed to ~/.local/share/gedit/plugins

On 07:03:58 AM January 15, 2012, Waldir wrote:

@edek: doesn't work for me (Ubuntu 11.10) and I tried placing it both in ~/.local/share/gedit/plugins (note: the gedit folder didn't exist, I created it myself) and /usr/share/gedit/plugins, to no avail; no menu entry, and no item in the plugin list (in the preferences dialog). Can you give some details on your system?

On 10:59:33 PM January 15, 2012, Jack David Baucum wrote:

Anyone using a Gnome 3 distribution needs to grab the port at also listed in the gedit plugins page at
Ubuntu 11.10+ uses Gnome 3.

On 09:11:46 AM January 17, 2012, edek wrote:


I use ubuntu 11.10.

That works for me (assume that your downloaded file is called regex.tar.gz):

tar xzvf regex.tar.gz
mkdir -p ~/.local/share/gedit/plugins
mv regex_replace ~/.local/share/gedit/plugins

start gedit

open preferences window, plugin should appear in the list

On 03:23:10 AM January 18, 2012, Nickleus wrote:

i made a one-stop tutorial for how to do this on ubuntu 11.10:

On 03:28:43 AM January 18, 2012, Nickleus wrote:

when i close the regex box then try and open it again it is blank. i have to restart it to get it working again.

On 10:48:49 PM February 06, 2012, Beright wrote:

Thanks for the plugin, very nice. For those complaining you can't replace with nothing, just type a space then delete it. Maybe that's something new though?

On 06:28:40 PM February 27, 2012, Menegazzo wrote:

Man, i tried everything to put your plugin to work:

Tried many folders, like usr/lib/gedit/plugins, ~/.local/share/gedit/plugins and ~/.gnome2/gedit/plugins and nothing.

I think my problem is because my gedit is V3. Can you help me with hints about what to do? I am really addicted to regular expressions, but really newbie on linux systems. So things like compile/build/make myself are still a mistery.

Thanks in advance

On 06:33:49 PM February 27, 2012, Jack David Baucum wrote:

Look at the above comments. The Gnome3 version of the plugin is at

On 05:10:17 AM February 28, 2012, Menegazzo wrote:

Sorry, i missed it!

I will try it at home.


On 04:24:29 PM February 28, 2012, Menegazzo wrote:

Working perfectly now. Congrats to Daniel d'Andrada T. de Carvalho and Ben Fisher, youre the guys. Because of your initiative, now i'm very tempted to learn a bit of python and plugin development.

On 02:08:41 AM February 29, 2012, Nickleus wrote:

*SWITCH* to geany if you want regex =) i've given up on gedit.

sudo apt-get install geany

On 02:01:00 PM March 12, 2012, markling wrote:

This is pretty damn cool. You've really saved the day.

I hope I may help by making a suggestion. Would you please make it key into Gedit's 'Undo' function? It presently undoes (gedit2) the action prior to the regex command, or indeed any number of regex commands. I could regex for half an hour but undo would still undo the op before the first regex command was executed and therefore wipe out the whole lot.


On 08:17:49 AM April 16, 2012, Evgenii wrote:
links to new version of this plugin look here:

download here:

On 08:39:40 AM May 08, 2012, Adam Victor Nazareth Brandizzi wrote:

Hi, Ben et al.

Some time ago, I forked this plugin and made some significant changes on it. It supports an accel key (Control+R), highlights found text, etc. Also, I put it in a bitbucket project, so I bet it will be easier to manage the various versions and to fork it:

BTW, I recently ported it to Gedit 3, which seems to be a very required feature - already provided by Jack Baucum, but anyway, it is available there too :)

On 10:01:00 AM September 18, 2012, passshok wrote:


I have gedit 3.4.1 on ubuntu 12.04 and I have some bugs with you plugin. Could you please fix it?

1. When I start gedit, the regexp dialog appears on screen for about 1 second and than it hides and gedit loads.
2. When I enter some text in regexp dialog in text field, I see no cursor blinking at all, text is editable, but no cursor indication!

Thank you! Nice day!

On 10:05:08 AM September 18, 2012, passshok wrote:

Thank you. It was fixed in previous comment.

On 12:40:50 AM October 16, 2012, Etienne Lawlor wrote:

I just wanted to mention this is a great plugin. I am just having this one issue. I am on Ubuntu 12.04 and using gedit v3.4.1.

The first time i open the plugin it works fine, then if i close it and try to open it back up in the same gedit session, i can only see the title bar of the dialog. When i go to expand the content below the title bar it appears all blank.

On 05:10:44 PM December 31, 2012, sam wrote:

Great hack, Ben-- you and Nickleus saved my day! --after spending half of it trying to get a regex S/R in gedit, with your help I have now accomplished something...

On 08:50:40 AM September 12, 2013, Bachsau wrote:

Updated Version for Pluma (MATE):