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

  1. John (author) :

    Jun 28, 2007 9:15 pm

    Kumpri, Search Regex is now a WP 2.1+ plugin only

  2. kumpri :

    Jun 15, 2007 12:19 pm

    hey,

    when i try to activate the plugin this is what i get: Fatal error: Call to undefined function: wp_enqueue_script() in /usr/share/wordpress/wp-content/plugins/search-regex/search-regex.php on line 33

    i am using WP2.0.10

    thanx in advance,

    kumpri

  3. Scott Vandehey :

    May 6, 2007 4:46 pm

    Thanks, it worked perfectly!

  4. John (author) :

    May 3, 2007 3:46 am

    Scott, try 1.4.2

  5. Scott Vandehey :

    May 1, 2007 7:35 pm

    Hi John,
    I get the same error as Phil.

    plugin: 1.4.1
    WP: 2.1.2
    PHP: 4.4.2

    I'm on Dreamhost, so I also tried changing the PHP version to 5.2.1, but I got the same results.

    Any help would be greatly appreciated!

  6. John (author) :

    Apr 16, 2007 1:48 am

    Bug fixed in 1.4.1

    Phil, what version of PHP are you using?

  7. author
    Martin :

    Apr 14, 2007 3:52 am

    Eeeks John, my comment has been stripped of its substance!
    the essence is that the final result is that a backslash is inserted before every occurence of a double-quote
    so that the final result is backslash-double-quote/wp/wp-content

  8. author
    Martin :

    Apr 14, 2007 3:45 am

    Hi,
    Sorry for a dumb question:
    If I have in a post a link to a picture as such:

    and I wish to just change the directory to /wp/wp-content/uploads/fleurs/
    If I enter into Search Regex
    Search string /iris/wp/wp-content
    Replace with /wp/wp-content
    then the search and replace visualisation is correct, but when telling the plug in to do the replace, the result is:

    Why the insertion of the back-slash everywhere?
    Thanks in advance for explanations and advice!

    I'm working with WP 2.12
    Kind Regards
    Martin

  9. author
    phil :

    Apr 10, 2007 10:30 pm

    ps

    i want to replace everything in the "alt"

    .jpg" alt=":::replace what ever is in here:::"

  10. author
    phil :

    Apr 10, 2007 10:22 pm

    i get this error when i try to use regex search

    Fatal error: Call to a member function on a non-object in /home/########/public_html/############/wp-content/plugins/search-regex/search-regex.php on line 50

    im using wordpress 2.1.2

    plugins:
    Adsense-Deluxe
    Counterize II
    Dagon Design Form Mailer
    External Links
    Google (XML) Sitemaps
    lbcd78 Meta Keyword Generator
    Peter's Custom Anti-Spam
    Postie
    Search Regex
    WordPress Database Backup
    WordPress Reports
    WP-PostRatings
    WP-PostViews

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