littlebigman Posted July 29, 2023 Posted July 29, 2023 Hello, I guess it's more a regex issue than specifically AutoIt, but just in case… The URL of a Youtube video can be plain ("https://www.youtube.com/watch?v=-123456") or hold other parameters ("https://www.youtube.com/watch?v=123456&list=PL-sOablah&index=6&pp=iAQB"). I tried the following regex to just grab the video's ID, but it doesn't work when it's the only parameter ;BAD $sURL = StringRegExp($sURL,"(v=(.+?)(&|$).",$STR_REGEXPARRAYMATCH) ;BAD $sURL = StringRegExp($sURL,"(v=(.+?)(&|\n).",$STR_REGEXPARRAYMATCH) ;BAD $sURL = StringRegExp($sURL,"(v=(.+?)(&|[\r\n]$).",$STR_REGEXPARRAYMATCH) What's the right way to tell the regex the pattern could be followed with either & or nothing? Thank you.
Andreik Posted July 29, 2023 Posted July 29, 2023 A simple google search and you get plenty of regex patterns to match YouTube video id. Just one of them: (youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)
Solution littlebigman Posted July 30, 2023 Author Solution Posted July 30, 2023 Thanks. This seems to work: $sURL = StringRegExp($sURL,"v=(.+?)(&|$)",$STR_REGEXPARRAYMATCH)
Andreik Posted July 30, 2023 Posted July 30, 2023 The pattern above probably match even some invalid YouTube video ids but whatever fit your needs.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now