How to extract YouTube video ID from a YouTube link
In this Bubble tutorial we demonstrate how to extract a YouTube video ID from a full YouTube URL. This video includes how to factor for YouTube shortened links and the presence of additional data (query strings) within the YouTube URL.
Unlock YouTube's hidden data: Learn how to extract video IDs from any URL format with our Bubble YouTube tutorial!
Master Bubble's find and replace: Discover how to handle multiple URL formats and extract crucial data using truncate functions.
Boost your Bubble skills: Extract YouTube IDs like a pro, even with tricky query strings!
Extracting YouTube Video IDs from URLs
In this quick Bubble tutorial, I'm going to show you how to extract a YouTube video's ID from a YouTube URL. This can be useful if you're embedding YouTube videos, depending on how you store that data in your database.
Using Find and Replace
One way to go about this is to use the find and replace function. I'm going to say input input a to refer to my input field value and then use find and replace. This is such a handy trick where you can find some text in a string in the input field and replace it with nothing.
Handling Different URL Formats
We have to cover many different eventualities as we can't always rely on our users inputting data in the same format. For example, what happens if they use the share URL, which is YouTube's link shortener? Let's copy that into here, and you'll see that it doesn't work. But what we can do is stack our find and replaces.
Dealing with Query Strings
There is another eventuality to cover, and that is if the URL has got some sort of query string at the end. For example, if we jump midway through the video and then say start from now, this is a query string related to time. But there could be other things to do with tracking and the source where people have arrived at the website from.
Using Truncate for Consistency
There's one final thing that I'd add, which is to truncate. Truncate means to trim our text, and YouTube video IDs are all 11 characters long. There's a really fascinating video by Tom Scott which we can link to, saying how YouTube is really unlikely to run out of video IDs - the math on it is astonishing.
Putting It All Together
We can say truncate to 11, so now if I paste in with the query string, it still only sticks to the first 11 characters of what's remained after we've done the find and replace. Let's just check this with our full URL. I'll add a query string here, and it still works because it removes everything in front of it, leaving only what's after this part of the URL. Then we can use truncate to limit what we return to just 11 characters.
Conclusion
This method allows us to extract YouTube video IDs consistently, regardless of the URL format or additional parameters. It's a useful technique when working with YouTube videos in your Bubble app.
The best way to learn Bubble.io?
Start building with total confidence
No more delays. With 30+ hours of expert content, you’ll have the insights needed to build effectively.
Find every solution in one place
No more searching across platforms for tutorials. Our bundle has everything you need, with 500+ videos covering every feature and technique.
Dive deep into every detail
Get beyond the basics with comprehensive, in-depth courses & no code tutorials that empower you to create a feature-rich, professional app.

Frequently Asked Questions
Find answers to common questions about our courses, tutorials & content.
No. Our Beginner Essentials course and AI No-Code Coach are designed for total newcomers. You’ll learn Bubble.io step by step - no coding required.
Simply type your question in plain English, and our AI taps into the entire video library to recommend the exact lessons you need. It’s like having a personal instructor on demand.
As long as you’re subscribed! With our monthly subscription, you get unlimited access to all 500+ videos, our growing course library, and the AI No-Code Coach.
Your subscription includes:
- Bubble Beginner Essentials – Get up and running fast.
- Build a ChatGPT Clone – Integrate AI into your no-code apps.
- Build Your SaaS Website with AI – Learn to create a scalable startup site.
Plus, new tutorials every week!
The AI No-Code Coach is your first stop for instant answers. If you need deeper help, you can book 1:1 Bubble coaching for expert guidance.
Yes! If you don’t see real progress within 14 days, let us know, and we’ll issue a full refund—no questions asked.
Absolutely. Your subscription is month-to-month, and you can cancel anytime—no lock-ins, no hidden fees.
Absolutely. Your subscription is month-to-month, and you can cancel anytime—no lock-ins, no hidden fees.
If you’re serious about building a successful SaaS startup, check out Mastery—our intensive mentorship program. Mastery goes beyond Bubble.io development and includes:
- 1:1 mentorship to fast-track your progress
- Marketing strategies tailored for no-code founders
- Product management insights to scale your startup
- Personalized support from experienced founders