Jump to content

[regex] Part could end with either & or nothing?


Go to solution Solved by littlebigman,

Recommended Posts

Posted

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.

Posted

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)\/))([^\?&"'>]+)

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...