-3

Possible Duplicate:
Javascript REGEX: How to get youtube video id from URL?

Is there a way with JS to take away like http://www.youtube.com and keep the id?

Example: http://www.youtube.com/watch?v=Y_UmWdcTrrc&feature=plcp to watch?v=Y_UmWdcTrrc&feature=plcp

Thanks!

Community
  • 1
  • 1
Xweque
  • 605
  • 1
  • 9
  • 29
  • If you don't want to get the ID only, just replace `http://www.youtube.com/` with an empty string. Or clarify your question... – Felix Kling May 13 '12 at 11:14
  • By being more precise. Do you want the Youtube ID or do you want to remove the protocol and host and only keep the path and query string? Also what does "save position" mean in your title? – Felix Kling May 13 '12 at 11:17
  • You can do it with regex: http://www.youtube.com/.*?, group 1. – Xyene May 13 '12 at 20:17

1 Answers1

0

You could probably do string manipulation via the indexOf and substring javascript functions to get the URL path like so:

var url = 'http://www.youtube.com/watch?v=Y_UmWdcTrrc&feature=plcp';
var path = '';

if (url.indexOf('.com/') != -1) {
    path = url.substring(url.indexOf('.com/') + 5);
}
abelito
  • 1,094
  • 1
  • 7
  • 18