Search Regex Plugin

Jun 12, 2006 | Tags: , , , | Written by Administrator

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/plugins on your server
  • Activate the plugin
  • Use Search Regex from the Manage/Search Regex menu

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:

Search Regex 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.

Preview

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.

Inline Replace

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.

Share This

Comments (page 5 of 10)

  1. author
    Rupert :

    Oct 21, 2007 6:55 pm

    The "readme.txt" inside the downloaded search-regex.zip says "…Upload `audit-trail` directory to your `/wp-content/plugins` directory.".

    But there isn't any 'audit-trail' folder in the zip.

    Did I miss something?

  2. author
    David M. Besonen :

    Oct 18, 2007 1:35 pm

    hi John,

    i just upgraded Search Regex from version 1.2 to 1.4.3 and noticed the source options had been greatly expanded. does this mean that it's not possible to search all sources simultaneously?

    and if not, how much work would it be to enable Search Regex to search all sources simultaneously?

  3. Rob :

    Oct 17, 2007 9:54 am

    John, I finally ran some tests. I didn't have that plugin yet installed. Wow! Firebug is great! Very revealing, sadly, of some of the errors I regularly get with other WP plugins. :o
    So, Search Regex isn't getting any errors at all during the process of double-clicking a red highlighted search result and editing manually. After the save, that search result grays out as if the manual edit "took" but another search reveals that what I edited didn't really get saved into the database. Odd.

    On another note, the links to the "Edit" and "View" in each search result are now pointing correctly. I resaved my permalink structure and that fixed all those links. I didn't catch that in your documentation, but you might make note of it.

  4. John (author) :

    Oct 17, 2007 1:06 am

    José, yes, it should be fine replacing many posts.

    Sparanoid, ping and trackbacks enabled. Not sure what you mean about an 'all content'

  5. José Luís :

    Oct 15, 2007 7:24 pm

    Hey, John! Have you tested your plugin about replacing many posts at the same time (using that "replace" link)?

  6. Sparanoid :

    Oct 15, 2007 9:17 am

    and...also the source from Comment Content, Comment author seems don't include the trackbacks and pingbacks neither.

  7. Sparanoid :

    Oct 15, 2007 9:09 am

    Hi John, your plugin is pretty good, but i found a little problem:

    The Source from 'Comment author URL' seems don't include the trackbacks and pingbacks, but i really want to replace something of them.

    And another suggestion, could you add a Source such as 'All Content'? i think i can save more time :)

  8. John (author) :

    Oct 15, 2007 3:56 am

    Rob, I understand you now and yes, that is not what is expected. Trying the same thing on my site I find that the text is replaced as expected, leading me to suspect that an error occurred when you save. If you have FireFox and Firebug installed you'll be able to see this error by clicking on the request and then clicking on the response.

  9. Rob :

    Oct 2, 2007 9:56 am

    John, I'm referring to double-clicking the red highlighted search results to enter manual edit mode. When I then change the text and click the save button, the little Mac-like spinning wheel does its thing and then that search result disappears as if my change "took". But visiting that page proves otherwise.

    Seems like the opposite behavior I'd expect.

  10. Pouya :

    Oct 2, 2007 8:32 am

    ohhh, so cool, try this, thank you soo much!

Leave a comment


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Home | Software | Terms & Conditions | Sitemap | John Godley © 2008
Close
E-mail It