#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\?(?:\S*?&?v\=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11})"
Local $sString = "Regular expressions can be a pain. This tool is designed to help developers learn, practice, and compose regular expressions." & @CRLF & _
"" & @CRLF & _
"## tests:" & @CRLF & _
"" & @CRLF & _
"// should not match" & @CRLF & _
"youtube.com/embed/v=0EWbonj7f18" & @CRLF & _
"youtube.com/e/v=0EWbonj7f18" & @CRLF & _
"youtube.com/attribution_link?u=/embed/v=0EWbonj7f18" & @CRLF & _
"youtube.com/attribution_link?u=/e/v=0EWbonj7f18" & @CRLF & _
"hey guys go to youtube and v=thisweird video i found" & @CRLF & _
"i found a youtube video on 4chan /v/foobarbaz" & @CRLF & _
"but we work at youtu.be and /thisweird video" & @CRLF & _
"" & @CRLF & _
"// short links" & @CRLF & _
"youtu.be/WijF8aivOo8" & @CRLF & _
"youtu.be/0EWbonj7f18" & @CRLF & _
"" & @CRLF & _
"// mixed" & @CRLF & _
"youtube.com/user/sandervandoorntv/watch?v=WijF8aivOo8" & @CRLF & _
"youtube.com/user/sandervandoorntv/watch?v=WijF8aivOo8&feature=related" & @CRLF & _
"youtube.com/user/sandervandoorntv/watch?feature=related&v=WijF8aivOo8" & @CRLF & _
"youtube.com/watch?v=0EWbonj7f18" & @CRLF & _
"youtube.com/watch?feature=related&v=0EWbonj7f18" & @CRLF & _
"youtube.com/watch?v=0EWbonj7f18&feature=related" & @CRLF & _
"youtube.com/embed/watch?v=0EWbonj7f18" & @CRLF & _
"youtube.com/embed/watch?feature=related&v=0EWbonj7f18" & @CRLF & _
"youtube.com/embed/v/0EWbonj7f18" & @CRLF & _
"youtube.com/e/v/0EWbonj7f18" & @CRLF & _
"youtube.com/e/watch?v=0EWbonj7f18" & @CRLF & _
"youtube.com/e/watch?feature=related&v=0EWbonj7f18" & @CRLF & _
"" & @CRLF & _
"// attribution link" & @CRLF & _
"youtube.com/attribution_link?u=/user/sandervandoorntv/watch?v=WijF8aivOo8" & @CRLF & _
"youtube.com/attribution_link?u=/user/sandervandoorntv/watch?v=WijF8aivOo8&feature=related" & @CRLF & _
"youtube.com/attribution_link?u=/user/sandervandoorntv/watch?feature=related&v=WijF8aivOo8" & @CRLF & _
"youtube.com/attribution_link?u=/watch?v=0EWbonj7f18" & @CRLF & _
"youtube.com/attribution_link?u=/watch?feature=related&v=0EWbonj7f18" & @CRLF & _
"youtube.com/attribution_link?u=/watch?v=0EWbonj7f18&feature=related" & @CRLF & _
"youtube.com/attribution_link?u=/embed/watch?v=0EWbonj7f18" & @CRLF & _
"youtube.com/attribution_link?u=/embed/watch?feature=related&v=0EWbonj7f18" & @CRLF & _
"youtube.com/attribution_link?u=/embed/v/0EWbonj7f18" & @CRLF & _
"youtube.com/attribution_link?u=/e/v/0EWbonj7f18" & @CRLF & _
"youtube.com/attribution_link?u=/e/watch?v=0EWbonj7f18" & @CRLF & _
"youtube.com/attribution_link?u=/e/watch?feature=related&v=0EWbonj7f18" & @CRLF & _
"" & @CRLF & _
"The HiFi RegExp tool is 100% JavaScript using jQuery. This tool was created by New Media Campaigns, the team behind HiFi, a next-generation CMS for web designers, developers, and agencies. Enjoy!" & @CRLF & _
""
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH)
Local $aFullArray[0]
For $i = 0 To UBound($aArray) -1
_ArrayConcatenate($aFullArray, $aArray[$i])
Next
$aArray = $aFullArray
; 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