Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 350103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:31:12+00:00 2026-05-12T11:31:12+00:00

My goal is to replace the links in the database with a catchall link.

  • 0

My goal is to replace the links in the database with a catchall link. I generally use the REPLACE command for replacing string in the database, but this time I am having difficulty because in order to find the links I need to use regular expressions, and that is simply not working out:

UPDATE node_revisions SET body = REPLACE ( `body` , 'http://.*.\pdf', '/migration-update' );

UPDATE node_revisions SET teaser = REPLACE ( `teaser` ,  'http://.*pdf', '/migration-update' );

These two queries just fall flat.

What needs to be done here in this situation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:31:12+00:00Added an answer on May 12, 2026 at 11:31 am

    As others have mentioned already, you can’t do this in MySQL. However, this appears to be a one time operation you need to do so I wrote you a quick and dirty little php script to do the job. It assumes your node_revisions table has a primary key column called ‘id’. If not, edit appropriately. Also, don’t forget to change the database host, username, password and database name at the top of the script to match your configuration.

    
    <?php
    $host = '127.0.0.1';
    $username = 'root';
    $password = 'password';
    $database = 'test';
    
    $conn = mysql_connect($host, $username, $password);
    
    if (!$conn) {
        echo "Unable to connect to DB: " . mysql_error();
        exit;
    }
    
    if (!mysql_select_db($database)) {
        echo "Unable to select " . $database . ": " . mysql_error();
        exit;
    }
    
    $sql = "SELECT * FROM node_revisions";
    
    $result = mysql_query($sql);
    
    if (!$result) {
        echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        exit;
    }
    
    if (mysql_num_rows($result) == 0) {
        echo "No rows found, nothing to print so am exiting";
        exit;
    }
    
    while ($row = mysql_fetch_assoc($result)) {
        $id = $row['id'];
        $body = $row['body'];
        $teaser = $row['teaser'];
        $body = preg_replace('/http:\/\/.*?\.pdf/', '/migration-update', $body);
        $teaser = preg_replace('/http:\/\/.*?\.pdf/', '/migration-update', $teaser);
        $sql = "UPDATE node_revisions set body='" . mysql_real_escape_string($body) . "', teaser='" . mysql_real_escape_string($teaser) . "' where id=" . $id;
        mysql_query($sql);
    }
    
    mysql_free_result($result);
    mysql_close($conn);
    ?>
    

    Note also that I used a non-greedy modifier on the regular expressions so that if you have multiple pdf urls in a body or teaser field, you won’t lose everything in between them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the goal: to replace all standalone ampersands with &amp; but NOT replace those
I need to parse a configuration file which looks like this (simplified): <config> <links>
So I have a string like this: string sampleString = this - is a
I know this question have been asked endless times but I can't find a
Goal Java client for Yahoo's HotJobs Resumé Search REST API . Background I'm used
Goal: Create Photomosaics programmatically using .NET and C#. Main reason I'd like to do
My Goal I would like to have a main processing thread (non GUI), and
My goal is to maintain a web file server separately from my main ASP.NET
My goal here is to create a very simple template language. At the moment,
my goal is to write a stored proc that can collect all field values

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.