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

  1. John (author) :

    Nov 2, 2008 8:46 am

    You must escape any regular expression characters using a backslash.

  2. author
    tomy :

    Oct 30, 2008 4:15 pm

    thanks for the great plugin but i have problem using this regex:

    ]*>(.*?)

    Error msg: Invalid regular expression: Unknown modifier ']'

    and when I tried to use:

    /]*>(.*?)/

    Error msg: Invalid regular expression: Unknown modifier 'p'

    how can i use it for html tags ?

  3. John (author) :

    Oct 1, 2008 7:10 am

    You've run out of memory and will need to increase it - some details can be found here

  4. Ricard :

    Oct 1, 2008 3:47 am

    I get this message when i work with this plugin: Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 1568345 bytes) in /mounted-storage/home95a/sub007/sc50212-SZBT/www/wp-content/plugins/search-regex/models/search.php on line 186

    How can get rid of this?

    //Ricard

  5. Tom Usher :

    Sep 25, 2008 1:47 pm

    Hi John,

    Thank you so much for your reply. It's a relief to hear that from someone who obviously knows what he's talking about. By the way, I did use your plugin to clean up my old-comment email address so that my comment avatar could start working properly again on all my comments on my site. I'm going to clean up all my old post titles that contain international characters that won't render properly in the Feedjit widget.

    What a great tool you've created. I recommend it.

    I'm not doing the regex with it, because I don't know enough about that yet and haven't had the time to learn it, so I can't speak to that part; otherwise, I can say it works really well. Thanks again.

    Blessings again,

    Tom Usher

  6. John (author) :

    Sep 23, 2008 1:43 pm

    Tom. adding a fulltext index to a table won't cause any harm other than using more space to store the data - you are basically telling MySQL to add an additional index to the guid field so it can perform faster searches. You can't add two indices to the same field so don't worry about having a duplicate index.

Pings & Trackbacks

1wordpress.com, alabase2.com, alexp.com.ua, alligatorcat.com, andersdenken20.de, blog.nanowings.de, cooperation.gensys-net.eu, d.teknoseyir.com, dltj.org, facemakers.stu.ru, imagensmix.com, ivangelion.tw, ldl.blog.dark-souls.ru, lifehacker.biz, mindman.1gb.ru, newsoft.com.ua, obezblog.com, parandroid.com, plasticdreams.org, prowordpress.org, russbiznes.com, shakin.ru, sparanoid.com, tecnoblog.net, triumphalroman.net, ultra.boy.jp, webloger.ru, wiki-futureforexwin.info, wordpressvn.com, wpmania.ru, wpstation.com, 1stwebdesigner.com, ayiva.com, blogpiloten.de, ccicenter.org, clarkburbidge.com, davepit.com, desperatelyseekingwp.com, devilsworkshop.org, freefullsoftwares.com, goodyao.cn, grandchild.jp, isaythat.com, lostnode.com, luxeseo.com, makadco.com, midasoracle.org, mr-foto.net, neurosoftware.ro, onecho.com, onu7.com, perraco.com, pi-kun.com, psicofxp.com, readers-edition.de, rehlaonline.com, seopost.ru, sjwets.nl, smashingmagazine.com, socialdailynews.com, themelab.com, tmthai.com, tommyholiday.ch, vasif.net, venukb.com, volkandesign.com, wordpresscn.com, wordpressplugin.org, wp-plugin-archive.de, zdaylan.com, zhangzhang.net, xuyiyang.com

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