I found this "[\\? &] V = ([^ & #] *)" on the Internet, can anyone explain this to me

I found a method on the Internet that can get youtube video id from url.

here it is.

var vid;
var results;
results = url.match ("[\\? &] v = ([^] *)");
vid = (results === null)? url: results [1];

The identifier will be contained in "vid".

What I do not understand, and I find it interesting and want to know this.

results = url.match ("[\\? &] v = ([^] *)");

How it works?

+5
source share
2 answers

, URL-. :

  • [\\?&] - . , &, ?. ( JavaScript-, , . - JavaScript, , , . .)
  • v= v=.
  • ( , , ) .
  • [^&#]* ( none) , & #. , , ^ , , . * , .
  • ) .

, , results[0] URL-, results[1] , .

+10

URL- youtube.

[\\?&]v=// ? v = & v =

([^&#]*)// #

results[1] ( , )

+1

All Articles