M
M
Maxim Kiktev2015-10-04 10:31:12
JavaScript
Maxim Kiktev, 2015-10-04 10:31:12

How to delete all characters up to the = sign along with the = sign itself in javascript from the address "www.youtube.com/watch?v=2XBwL_KEpgk"?

How to delete all characters before the = sign in javascript from the address " www.youtube.com/watch?v=2XBwL_KEpgk " along with the = sign itself?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alex K, 2015-10-04
@Ne0lite

Here is a function to extract the video id from a youtube link:

function getVideoID(url){
  var id = '';
  url = url.replace(/(>|<)/gi,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
  if(url[2] !== undefined) {
    id = url[2].split(/[^0-9a-z_\-]/i);
    id = id[0];
  }  else {
    id = url;
  }
  return id;
}

Returns the video ID not only in the scenario you suggested, but also in many others:
/*
* Поддерживает ссылки вида:
var url = 'http://youtube.googleapis.com/v/4e_kz79tjb8?version=3';
url = 'https://www.youtube.com/watch?feature=g-vrec&v=Y1xs_xPb46M';
url = 'http://www.youtube.com/watch?feature=player_embedded&v=Ab25nviakcw#';
url = 'http://youtu.be/Ab25nviakcw';
url = 'http://www.youtube.com/watch?v=Ab25nviakcw';
url = '<iframe width="420" height="315" src="http://www.youtube.com/embed/Ab25nviakcw" frameborder="0" allowfullscreen></iframe>';
url = '<object width="420" height="315"><param name="movie" value="http://www.youtube-nocookie.com/v/Ab25nviakcw?version=3&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/Ab25nviakcw?version=3&amp;hl=en_US" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>';
url = 'http://i1.ytimg.com/vi/Ab25nviakcw/default.jpg';
url = 'https://www.youtube.com/watch?v=BGL22PTIOAM&feature=g-all-xit';
url = 'BGL22PTIOAM';
*/

V
Vitaly Inchin ☢, 2015-10-04
@In4in

I'm looking at the answers above .... I'm in shock, guys, or I don't understand something ...
One riveted regular expression, the other answered PHP in general, the third one wants to cut off by the number of characters. Poor line...

var inputString = "www.youtube.com/watch?v=2XBwL_KEpg";
alert(inputString.split("v=")[1]);  //2XBwL_KEpg

F
frees2, 2015-10-04
@frees2

$fulluri = preg_replace("/\?.*/i",'', $_SERVER['REQUEST_URI']);
$ww =strlen($fulluri) ;
 if ($ww >14  xor $ww ==54 xor $ww ==38 xor $ww ==33 )   { header("HTTP/1.1 301 Moved Permanently");header( 'Location: /v', true, 303 ); exit(); };
$fulluri = strip_tags($fulluri); 
$fulluri = trim($fulluri);
$ww = $fulluri;
$fulluri =  substr($fulluri, 3, 11);
$ww =  substr($ww, 14, 54);

www.dulsky.eu/v/BobNpsLaNl0

B
bio, 2015-10-04
@bioforge

"www.youtube.com/watch?v=2XBwL_KEpgk".replace(/(^.+=)/,'')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question