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!

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

4 Comments

Not stellar, but I think I have an idea of the logic you are thinking of suggesting... :)
Or plan B... how much data do you have? - could you rip it into CSV, process it as text and then upload?
hmmm... interesting idea. I may just try that! Thanks!
You could easily pull it into Textpad, etc. Gimme a shout if you need help with Regex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.