2

Wondering if someone could help with out with creating a regex..

Basically, taking an iFrame's src, and seeing if it's from SoundCloud. If it is, return its id. For example:

var src = 'http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F85110490&auto_play=false&show_playcount=false&show_user=false&show_comments=false&buying=false&liking=false&sharing=false&show_artwork=false&color=00e7ff';

function soundcloudId(src) {
   var p = /___________/;
   return (src.match(p)) ? RegExp.$1 : false;
}

soundcloudId(src);

And as a result, it would run the "src" through the regex, and if a soundcloud link, would return 85110490. Otherwise, false.

lifwanian
  • 644
  • 1
  • 7
  • 19
  • 1
    Do you mean that the value returned should be 85110490? The 2F is part of the %2F escape sequence. – Mike Mertsock Mar 27 '13 at 04:03
  • @Cfreak The only Soundcloud regex I found was: var p = /^https?:\/\/(?:www.)?soundcloud.com\/[A-Za-z0-9]+(?:[-_][A-Za-z0-9]+)*(?!\/sets(?:\/|$))(?:\/[A-Za-z0-9]+(?:[-_][A-Za-z0-9]+)*){1,2}\/?$/i; But it doesn't work with embeds... – lifwanian Mar 27 '13 at 04:08

1 Answers1

2

Try this regex:

/http:\/\/w.soundcloud\.com\/.*%2Ftracks%2F([0-9A-F]+)/

Runnable example: http://jsfiddle.net/mYf6P/

Mike Mertsock
  • 11,825
  • 7
  • 42
  • 75