Search Regex Plugin
Search Regex adds a powerful set of search and replace functions to WordPress. These go beyond the standard searching capabilities, and allow you to search and replace almost any data stored on your site. In addition to simple searches you have the full power of PHP's regular expressions at your disposal.
The driving force behind this plugin is to aid in website migration and upgrading. If you've ever done either of these then you know the pain of having to go back through all your data, changing URL paths and fixing things. With this plugin you can reduce this work to a search and replace pattern and the job is finished in seconds.
Why would you want this? The primary reason for the plugin was to aid in relocating directories. It's a real pain to manually go through every post and change image directory names. With this plugin all that was required was a simple search and replace pattern, and the job was finished in a few seconds.
Features include:
- Simple search and replace
- Advanced regular expression search and replaces, including back references and capture groups
- Search previews with inline replacing
- Perform searches in post & page content, excerpt, titles, URL, and meta-data, as well as comment content and author data
- Full support for WordPress roles. You can only search and replace in posts you have access to
- Fully localized
Get the Flash Player to see this movie.
Version History
- 1.4.8 - Update base library. Fix issue with regex not being selected
- 1.4.7 - Fix for 2.6 versions
- 1.4.6 - Added tag & sniplet searching. Make work in Safari
- 1.4.5 - Add search regex capabilities ('search_regex_read' and 'search_regex_write'). Fix meta values
- 1.4.4 - Fix escaping issue, allowing search limit and direction
Installation
Installation is just like any WordPress plugin:
- Download search-regex.zip
- Unzip
- Upload directory to
/wp-content/pluginson your server - Activate the plugin
- Use
Search Regexfrom theManage/Search Regexmenu
You can find full details of installing a plugin on the plugin installation page.
Usage
Searches can be performed from the Search Regex submenu, contained within the main Manage menu of the administration interface. Once there you will be presented with the following interface:
The search and replace patterns are, as you would expect, where you enter what you want to search for and what you want to replace it with. Several options exist to refine the searching capabilities, which will be explained later. You can also chose the data source.
When you have entered your patterns you need to press one of the search buttons:
- Search - Just do a search and show the results
- Replace - Perform a search and replace, but only show the results. The database is not changed.
- Replace & Save - As Replace, but the replacements are saved back into the database.
It should be noted that while you can enter any search pattern in a simple search, you must adhere to regular expression syntax when the regular expression mode is enabled. The plugin will detect any regular expression errors and warn you.
If you wish to remove a search pattern (i.e. search for 'cheese' and delete the any occurrences) then you can leave the replacement pattern empty.
Search Options
The following options modify the search:
- Regex - Enable regular expressions. Note that the search pattern can now only contained properly escaped characters. The @ character is used as a delimiter and also needs escaping.
- Case-less - Case insensitive search
- Multi-line - Enables multi-line mode (see PHP's pattern modifiers page)
- Dot-all - Enables the dot-all mode (see PHP's pattern modifiers page)
Results
Search results as presented as a list of found occurrences. Each result is shown in context with the surrounding data and, if enabled, the replacement context is also shown.
Depending upon the data source you have options to view, edit, or replace the data. Additionally, if you double-click on the highlighted search or replace patterns then an inline edit box will appear allowing you to directly edit the data.
Examples
The simplest case is changing paths:
/wp-images/
to
/images/
A more complicated regular expression version to only move PNG images:
/wp-images/(.*?).png
to
/images/png/$1.png
Warning
You should always use the Search & Replace preview before saving to the database. I will accept no responsibility for any damage caused to your data. If you are in any doubt then backup your database first.
Support
Please direct all support questions to the Search Regex support forum. Any support questions left on this page may not be answered.
Bugs & New Features
A full list of all bugs can be found in the Search Regex issue tracker.
| Date | Current requested features |
|---|---|
| 29 Mar 2008 | Add checkboxes to replace search-results |
| 06 Apr 2008 | Replace with newline |
A full list of all requested features can be found in the Search Regex feature tracker.






Comments (page 2 of 10)
Feb 27, 2007 8:02 pm
I'm a little confused and I hope you can help me. I use regex and multiline to do this:
Search: \n\nTEXT
To this:
Replace: TEXT\n\n
But the result comes out to TEXT\n\n as actual characters rather than linebreaks. Can you help?
Feb 27, 2007 9:07 am
Thanks for the plugin - I wanted to copy all my IMG tags with just the ALT attributes to have TITLEs too, equal to the ALT, and your plugin did it for me in just a few seconds!
I have a few other SEO-related mass edits I want to do too.
Jan 26, 2007 4:20 am
Hi there,
using wpmu 1.1 and I have no luck using your plugin. What I am trying to do is the following:
I had to change the plugin which did my seo optimizing for me, the old one was adding metadata to each post called head_description and as content it put the posts or pages description in there. the new plugin does not use head_description but plain and simple description...
so I thought I could search for head_description and replace by description, but when I search in metadata it tells me“: nothign found....
is this the wrong way? do I have to use phpmyadmin for this kind of search?
Dec 16, 2006 3:01 am
sorry, third comment in a row...
I tried to understand the problem to no avail. Anyway I am pretty sure there is something wrong with the use of htmlentities.
In fact, using the double quote in the replace pattern will not only result with actually *seeing* the backslashes inside the edit post page. When I go to check the final code, I find that all the backslashes and the quotes are converted into html entities (that's why they won't go away and any replacement that adds code with quotes gives broken results).
Somehow the data must be fired up into the database with html entities attached and not actual backslashes. I don't understand where this happens though.
I noticed that you use htmlentities both in the form fields and in the replace function so, it could be there. But I'm no real expert (I'm a total newbie actually).
( and in fact I am going to download my database and again perform all replacements with a text editor for now )
Dec 16, 2006 12:49 am
ps. the third problem become obvious if you want to substitute a simple word, such as 'blog' with a piece of code that wasn't there before, such as .
The result will be
and the picture won't show.
Dec 16, 2006 12:44 am
Thanks for this plugin! Especially the opportunity to check out the results before saving any real change is great.
Only three things:
--I'd love to be able to replace text also from titles...
--If a blog is in a secondary folder (for example yoursite.com/blog) the links to edit the posts in the result list won't work...
--If I put code as the replace pattern, searchregex will add the backslash characters, and they will remain even into the edited post, causing banal code such
Nov 2, 2006 2:17 am
Hey,
This plug-in just saved my life. Wow! Was having to edit hundreds of posts by hand to fix bad html and this plugin just allowed me to fix all of them in less than 30 seconds.
Thank you so much!
Will
Aug 13, 2006 10:52 pm
It really depends on your source code. If you have something unique at the start and end of the code then you can do something like:
Search: stringatstart(.*?)stringatend
Replace: <code>$1</code>
Regular expressions are an enormously complicated subject, so you may be better of looking for a tutorial on them.
Aug 9, 2006 5:36 pm
I want to replace following from each post:
some src code
With
<code>some src code</code>
What search and replace pattern I need to use
I can replace with <code> but then how do I match with </code> as post have more tag located
Jul 30, 2006 9:16 pm
This plugin saved me from a major headache after moving my blog to my root directory from a subdirectory. Thanks so much!
Leave a comment