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 6 of 10)
Nov 7, 2007 8:38 pm
The order is whichever direction the 'order by' field is set to, and if you set it to 100 ascending then it will be the first 100 posts, and 100 descending it will be the last 100.
Nov 7, 2007 7:10 am
the "Limit to:" (a.k.a. 'faux-limit') options are 10, 25, 50, 100, or 'No limit'.
in what order is the faux-limit (chronological, reverse-chronological, random) and is it complete (i.e. assuming the faux-limit is 100 and the order is reverse-chronological, then the 100 most recent entries would be searched)?
Nov 7, 2007 3:24 am
Regards the faux-limit. Due to the way the search works the limit is on the number of posts that are looked at, not the number of results. The distinction is because the searching is done inside the plugin, not in the database. This means that although only 10 posts may be looked at, each post may generate hundreds of search hits. This isn't ideal, but is certainly the cheapest and quickest method given the current plugin architecture.
Nov 7, 2007 3:16 am
on Nov 6, 2007 5:16 am, John (author) wrote:
> David, I've fixed that bug and add the ability
> to change the order direction,
thank you.
> as well as put a faux-limit on the number of
> results (this limits the number of posts/comments
> searched, not the number of results returned).
i don't grok the distinction you are attempting to convey. could you re-explain using different words?
> I haven't done any paging as this would require a
> major change to the plugin.
ok
Nov 6, 2007 5:16 am
David, I've fixed that bug and add the ability to change the order direction, as well as put a faux-limit on the number of results (this limits the number of posts/comments searched, not the number of results returned). I haven't done any paging as this would require a major change to the plugin.
Rob, try the new version and putting a limit on the results. A blank page is typically a sign of no more memory.
Nov 3, 2007 4:00 am
John,
can the output of search-regex be displayed in reverse-chronological order?
and can the output be kept to 50 results/page?
Nov 1, 2007 1:17 pm
hey John,
i have what seems to be a bug to report:
when performing a regex search with "\b": /\bcow\b/
the correct results are returned, but the search field changes to /bcowb/ (notice the missing escape characters) after the search completes. intuitively i expect the same search string to remain in the search field. is this behavior intentional?
P.S.
is there a bug tracker for this plugin?
Oct 29, 2007 11:29 am
John, This seems like the ideal plugin for some work I need to do but I'm having some problems. I can search post titles for whatever but when I try to search post content the page churns for a little while then claims to be done but leaves me with a blank screen (just the admin header showing). My blog has around 500 posts. Any ideas?
WP 2.3.1, plugin 1.4.3.
Oct 27, 2007 7:18 am
Oh this was awesome too - helped me strip out all the / markup I had put in my posts from WP 1.5 after upgrading to WP 2.3 where tag support is integrated. Saved me from an ugly clean-up job, cheers!
Oct 23, 2007 10:17 pm
Rupert, a copy-and-paste error! The correct directory is 'search-regex'.
David, it was never possible to search all sources at the same time. I'll have a look at doing this, but suspect it may involve some structural changes.
Leave a comment