0

I'm trying to update a Wordpress table (wp_posts) that is using a URL with a two digit random number between 10 and 20 inside the URL to a new URL for a move to a new CDN. Here is an example of what I am trying to do:

UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://media13.oldcdn.com', 'http://newcdn.com');

That's fine and would (I believe) work well for what I want to accomplish except the number 13 in the example above could be any number between 10 and 20.

I think that I want something like this (but I am not savy in the ways of the database):

UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://media REGEXP '\d\d' .oldcdn.com', 'http://newcdn.com');

Please help!

jonathanbell
  • 2,507
  • 5
  • 23
  • 40

1 Answers1

2

SQL supports wild cards in query strings in where clauses - e.g.

LIKE 'http://media__.oldcdn.com' 

but not in Replace - you'll probably need a script for what you're trying to do. I found a solution here: How to Use Regexp in MySQL Replace Commands?

Community
  • 1
  • 1
web_bod
  • 5,728
  • 1
  • 17
  • 25