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!
SQL supports wild cards in query strings in where clauses – e.g.
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?