P
P
ponoroshca2021-08-24 11:43:24
Regular Expressions
ponoroshca, 2021-08-24 11:43:24

Replacing youtube url with video frame in Sublime text 3 in html?

Hello experts! I have lines of text like:

<a target="_blank" href="https://www.youtube.com/watch?v=pahhmV4WUUU">


I need to do a replace in sublime text 3 like:

<iframe width="560" height="315" src="https://www.youtube.com/embed/pahhmV4WUUU" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>


That is, do not touch pahhmV4WUUU and there are a lot of such links. I

broke my head how to do it already, I tried regular expressions, but it still doesn’t work!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-08-24
@ponoroshca

find:

<a [^>]*href="https://www\.youtube\.com/watch\?v=([^"&]+)[^>]*>(?s:.*?)</a>

replace:
<iframe width="560" height="315" src="https://www.youtube.com/embed/$1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

https://regex101.com/r/n5KA8s/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question