+ 1

ReGex problem for YT Ids catching

Hi, i was looking for a regex that would allow me to get the ids of videos and contents from YouTube, and I found this: https://regex101.com/r/OY96XI/1 However, I noticed that by entering incorrect URL addresses, they were considered as false positives. (The addresses are at the bottom of the page). I also noticed that the last address among the correct ones is not captured. Does anyone know how to correct the error of this regex? I was writing one of my own, then I found this much more effective and complex. Modified regex: https://regex101.com/r/iFiHnt/1

19th Nov 2024, 10:15 PM
Mick
Mick - avatar
5 Answers
0
I've finished writing the regex, based on the forked one, if you want to do some tests on working URLs I'd be grateful, otherwise it should be able to catch most of the YT addresses correct or almost. https://regex101.com/r/hrLz72/32
22nd Nov 2024, 9:56 PM
Mick
Mick - avatar
+ 4
Hi, Test this one: (?:https?:\/\/)?(?:www\.|m\.)?(?:youtube\.com\/(?:watch\?v=|embed\/|v\/|e\/|user\/.*#p\/u\/\d+\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})
20th Nov 2024, 11:10 AM
Per Bratthammar
Per Bratthammar - avatar
+ 1
Thank you
20th Nov 2024, 5:26 PM
Mick
Mick - avatar
0
I'm new to regex, if there was a way to remove all those groups, it would be better to read (without obviously taking away the effectiveness of the regex)
22nd Nov 2024, 9:58 PM
Mick
Mick - avatar
0
Some graphics card gives this option
22nd Nov 2024, 10:57 PM
Claudienne Oliveira