Search and Replace Plugin (CMSR) - Use Case - Example of Regex and Storing Results In the Database


Use Case - Example of Regex and Storing Results in the Database

Back to User Guide

Note: This guide covers features from:

Video Use-Case


Introduction

The Search and Replace plugin allows you to easily replace text in all types of posts and pages, including theme and plugins generated content. 

It works via rules: you tell it  "x" should become "y". Then, everytime a visitor visits a page with "x", he/she will see "y". 

Note that the content will only change to the visitor. By default the change will not be applied to your database.

Use Case Front-End

Creating a Regex rule that removes all capital letters:

Creating a Regex rule that removes all capital letters - WordPress Plugin to Mass Replace Links
Creating a Regex rule that removes all capital letters

Result on the front-end:

Result on the front-end - Mass Replace Text in WordPress
Result on the front-end

Committing permanent changes to the database using the rule:

Committing permanent changes to the database using the rule - Search and Replace Plugin
Committing permanent changes to the database using the rule

Committing permanent changes to the database using the widget:

Committing permanent changes to the database using the widget - WordPress Plugin Search and Replace
Committing permanent changes to the database using the widget

Use Case Assumptions

In this example use case guide, we'll consider an example of Regex and how to store results in the database. 

We consider that you have already bought the plugin, but not installed it. 

It follows:

Installing the Plugin

The process is the same for all CM plugins.

CreativeMinds Customer Account Dashboard - Downloads tab
CreativeMinds Customer Account Dashboard
  • Download the plugin from your customer dashboard.
  • Log in to WordPress and navigate to the WordPress Admin  → Plugins settings.
  • Click on Add New.
  • Activate it and add the license.

Learn more: Getting Started - Plugin Overview


Quick Recap

If you still have question with these steps:

  • Installing the plugin
  • Creating Replacement Rules
    • Base Configuration
    • Restrictions
      • Timeframe
      • Exclusions
  • Settings
  • Replacement Widget
  • Export/Import 

Then check the guide: Search and Replace Plugin (CMSR) - Use Case - How to Replace Content On the Fly

Using Regex

A regular expression (abbreviated regex or regexp and sometimes called a regular expression) is a sequence of characters that define a search pattern, mainly to use in pattern matching with strings, or string matching. 

Let's consider a simple example: we need to remove all capital letters from the content. We can use this regular expression for it:  /[A-Z]/

To create a rule, navigate to Admin Dashboard → Search & Replace → Settings.

Navigation to the plugin settings - WordPress Plugin Search Database and Replace
Navigation to the plugin settings

Under the Replacement Rules tab find a dashboard for creating rules at the bottom of the page.

To create a Regex rule, do the following:

  1. Put /[A-Z]/ to the From String area.
  2. Keep empty the area To String.
  3. Make sure to enable the checkbox Regex.
  4. Choose the Location where to commit the rule (optionally)
  5. Click Add New Rule to create a rule.
Example of the regex replacement rule - Find and Replace Plugin WordPress
Example of the regex replacement rule

Now let's check the result on the front-end. To showcase this example clearer, we will use the Replacement Widget that allows enabling or disabling replacements on the Front-end.

Example of the regex replacement on the front-end: removing capital words - WordPress Plugin to Mass Replace Links
Example of the regex replacement on the front-end - removing capital words

As you can see - all capital letters are removed.

TIP: Learn More About Regex

Some examples of Regex resources:

You can use Regex in the search and replace rules to create more specific and defined replace rules.

Saving Permanent Changes to the Database

By default, the plugin does not make permanent changes to your content. Once you create replacement rules, they will be applied to visitors only while they access the page.

There are two ways how to commit permanent changes to content:

  • Using the replacement rule
  • Using the replacement widget.

Saving Permanent Changes Using the Rule

To commit permanent changes using the rule, you need to click the button UpdateDb for the relevant rule. Be careful, as this method commits permanent changes to the database for all posts that are included in the Location field (or for all except the excluded ones).

When you click the button UpdateDb a pop-up message will appear with a warning. If you are sure about it, click Ok.

Commiting permanent changes to the database - Mass Replace Text in WordPress
Commiting permanent changes to the database

As a result, the post on the back-end is changed according to the rule:

Result - Search and Replace Plugin
Result

Saving Permanent Changes Using the Widget

Another way for committing changes is using the Replacement Widget. To make it work, head to the Replacement Widget tab.

Choose the option Show to admin only in the Display Widget for dropdown. One more option will appear - Admin can save changes to database. You need to enable it too.

Enabling front-end widget for admin only - WordPress Plugin Search and Replace
Enabling front-end widget for admin only

Don't forget to click the button Save Changes at the bottom of the page.

Saving the changes - WordPress Plugin Search Database and Replace
Saving the changes

As a result, the admin will see the button Make changes permanent in DB on the posts with replacements.

This widget commits permanent changes only to the specific post where it used. Be careful, as there is no warning message when you click on it.

Applying permament changes to DB using the front-end widget - Find and Replace Plugin WordPress
Applying permament changes to DB using the front-end widget

Let's see how it works:

Result - WordPress Plugin to Mass Replace Links
Result

End Result

Following instructions found in the Search and Replace plugin and guides, you should be able to create Regex rules and commit permanent changes to the database.

Use Case Front-End

Creating a Regex rule that removes all capital letters:

Creating a Regex rule that removes all capital letters - Mass Replace Text in WordPress
Creating a Regex rule that removes all capital letters

Result on the front-end:

Result on the front-end - Search and Replace Plugin
Result on the front-end

Committing permanent changes to the database using the rule:

Committing permanent changes to the database using the rule - WordPress Plugin Search and Replace
Committing permanent changes to the database using the rule

Committing permanent changes to the database using the widget:

Committing permanent changes to the database using the widget - WordPress Plugin Search Database and Replace
Committing permanent changes to the database using the widget

More information about the Search and Replace Plugin for WordPress

Other WordPress products can be found at CreativeMinds WordPress Store

Let us know how we can Improve this Product Documentation Page

To open a Support Ticket visit our support center
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.