#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?x)#" & @CRLF & _
"# Inspired by http://stackoverflow.com/questions/6556559/youtube-api-extract-video-id" & @CRLF & _
"# Example: https://www.youtube.com/watch?v=o8QuLYXKNCg&rel=0&autoplay=1" & @CRLF & _
"#" & @CRLF & _
"# Match any youtube URL" & @CRLF & _
" (?:https?://)? # Optional scheme. Either http or https" & @CRLF & _
" (?:www\.)? # Optional www subdomain" & @CRLF & _
" (?: # Group host alternatives" & @CRLF & _
" youtu\.be/ # Either youtu.be," & @CRLF & _
" | youtube\.com # or youtube.com" & @CRLF & _
" (?: # Group path alternatives" & @CRLF & _
" /embed/ # Either /embed/" & @CRLF & _
" | /v/ # or /v/" & @CRLF & _
" | /watch\?v= # or /watch\?v=" & @CRLF & _
" ) # End path alternatives." & @CRLF & _
" )? # End host alternatives." & @CRLF & _
" ([\w-]{10,12}) # Allow 10-12 for 11 char youtube id." & @CRLF & _
" (?:[&?](.*)) # Optional Parameters" & @CRLF & _
" $"
Local $sString = "https://www.youtube.com/watch?v=o8QuLYXKNCg&rel=0&autoplay=1&autoplay=2&autoplay=3&autoplay=4"
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYFULLMATCH)
; Present the entire match result
_ArrayDisplay($aArray, "Result")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm