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 4 of 10)

  1. John (author) :

    Oct 2, 2007 7:04 am

    Hi Rob,

    Yep, that's because the 'search' and 'search and replace' only show you the results (allowing you to view the results first). If you want the data to be changed in the database then you need to use the 'replace and save' button.

    Thanks Stanley, there may well be an issue with the order of the options!

  2. Rob :

    Oct 1, 2007 2:35 pm

    Hmm, I'm experiencing some difficulty with searches on a bunch of unicode corruption throughout my blog. Somewhere along the line (probably during a WP update), some unicodes like "é" got replaced by "é". Very odd and annoying. Enter Search Regex!

    What I'm seeing though is that if I do a Search and manually change the instances that are found, or if I do a Replace and approve each instance replacement, neither actually save into the database. It appears to work (no errors reported), but no change either.

    Now if I do a Replace & Save, that will work. But of course it's a little bit scarier!

    Any ideas why?

  3. author
    Stanley :

    Sep 29, 2007 1:59 pm

    Great plugin! But there's something odd with the options!? In my case the dot all option didn't work (php5.2). I changed

    function set_regex_options ($dotall, $case, $multi)
    {
    $this->regex = true;
    if (!empty ($dotall))
    $this->regex_options .= 's';

    if (!empty ($case))
    $this->regex_options .= 'i';

    if (!empty ($multi))
    $this->regex_options .= 'm';

    }

    to

    function set_regex_options ($dotall, $case, $multi)
    {
    $this->regex = true;
    $this->regex_options .= 'ism';

    }

    That works for me!
    Maybe it's the order!? 'ism' and not 'sim'? Didn't have time to have a deeper look into it ;)

  4. Rob :

    Sep 24, 2007 11:04 pm

    I'm testing the plugin now and noticed that the comment results list returns links to generic archive pages, not the post pages. For instance, I have one comment #32371, but the "view post" link points to the monthly archive it belongs to.

    Could this be a permalink setup issue?

  5. Rob :

    Sep 24, 2007 7:32 pm

    Oh, my gosh, this is just fantastic! And I agree with BAS. Your plugins aren't just really functional -- they're very, very pretty. And that goes a long way, seriously.

    Up until now, I'd been using a plugin called Search & Replace. In a word: "ugg". No care to warning the user of what it was about to do. Let's just say, thank goodness I'd made a database backup ahead of time.

    Yours is 10, 50, 1000 times more powerful. I only wish I'd found yours long ago! As I'm admittedly a "tweaker", i.e., I tend to change plugins more than I should, I have to change the associated tag codes. This is perfect for such a thing.

    Thanks!

  6. John (author) :

    Sep 23, 2007 5:41 am

    Try downloading again, there was a temporary server glitch

  7. TSUDA Fumika :

    Sep 21, 2007 10:39 pm

    I try to download, it says "File not found".

  8. mandarine :

    Sep 1, 2007 1:12 am

    That's awesome. Thank you soo much.

  9. BAS :

    Aug 17, 2007 2:51 pm

    Dude, this rocks.

    I love the way you put effort in making the plugins look great. You are the plugin master!

  10. author
    joetke :

    Jul 3, 2007 10:25 am

    Whaooo!!!
    I DO LIKE your GREAT JOB ! This plugin is a MUST and is so FAST !!!
    You really deserve donations ! I'll remember that ;)

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