I have 2 urls from soundcloud that I would like to get everything after the /(or).sc/, I don't understand regex at all, I could do the javascript match/replace, only problem is the http vs https
Any help would be much appreciated.
Here's what I've got, not sure how to do the https of the replace or if this is the best way to approach this...
function getSoundCloudInfo(url){
return url.replace("/", "").replace("/", "");
}
I have 2 urls from soundcloud that I would like to get everything after the .com/(or).sc/, I don't understand regex at all, I could do the javascript match/replace, only problem is the http vs https
https://soundcloud.com/ilyao/lyao-lj-mtx-and-lj-mtxs-hair
http://snd.sc/1cvgIjv
Any help would be much appreciated.
Here's what I've got, not sure how to do the https of the replace or if this is the best way to approach this...
function getSoundCloudInfo(url){
return url.replace("https://soundcloud.com/", "").replace("http://snd.sc/", "");
}
Share
Improve this question
edited Aug 14, 2013 at 9:34
Brian Putt
asked Aug 14, 2013 at 8:48
Brian PuttBrian Putt
1,3484 gold badges16 silver badges33 bronze badges
2
- Could you show us what you have tried ? – HamZa Commented Aug 14, 2013 at 9:24
- 1 @HamZa I just added what I'm currently using – Brian Putt Commented Aug 14, 2013 at 9:34
4 Answers
Reset to default 7function getSoundCloudInfo(url){
var regexp = /^https?:\/\/(soundcloud\.com|snd\.sc)\/(.*)$/;
return url.match(regexp) && url.match(regexp)[2]
}
It is too late, but...
Don't forget about:
- mobile version (
m.
after http(s)://) - possible slash at the end
- with or without
SSL/TLS
, so it can behttp
orhttps
- with or without
www
So, full regex is:
^(https?:\/\/)?(www.)?(m\.)?soundcloud\.com\/[\w\-\.]+(\/)+[\w\-\.]+/?$
((https:\/\/)|(http:\/\/)|(www.)|(m\.)|(\s))+(soundcloud.com\/)+[a-zA-Z0-9\-\.]+(\/)+[a-zA-Z0-9\-\.]+
const FULL_YOUTUBE_REG_EXP = /^(?:(https?):\/\/)?(?:(?:www|m)\.)?youtube\.com\/watch.*v=([a-zA-Z0-9_-]+)/
const SHORT_YOUTUBE_REG_EXP = /^(?:(https?):\/\/)?(?:(?:www|m)\.)?youtu\.be\/([a-zA-Z0-9_-]+)/
const VIMEO_REG_EXP = /^(?:(https?):\/\/)?(?:www\.)?vimeo\.com\/(\d+)/
const SOUNDCLOUD_REGEXP = /^(?:(https?):\/\/)?(?:(?:www|m)\.)?(soundcloud\.com|snd\.sc)\/(.*)$/