0

I want to change this:

<iframe width="850" height="478" src="https://www.youtube.com/embed/4zH9Zca1vRM" frameborder="0" allowfullscreen></iframe>

For this:

https://www.youtu.be/4zH9Zca1vRM

For every iframe of youtube video in the database. What is the right sentence for do it? I gess something like this:

step 1. Replacing first part:

wp search-replace '<iframe width="*" height="*" src="https://www.youtube.com/embed/' 'https://www.youtu.be/'  --regex

step 2. Replacing last part:

wp search-replace '" frameborder="0" allowfullscreen></iframe>' ''  --regex

Is it right? I'm not sure about quotes and wildcards.

Thank you!

0

You should probably use something like regex101.com to test this before you run it on a database.

You could start off with something like:

wp search-replace '<iframe ((width|height|frameborder)="\d+" |allowfullscreen)+?src="https?:\/\/www\.youtube\.com\/embed\/([a-zA-Z0-9]+?)" ((width|height|frameborder)="\d+" |allowfullscreen)+?>\<\/iframe\>' 'https://www.youtu.be/$1' --regex

but I'm not 100% sure of that...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.