0

I have a consistent URL along the lines of: http://www.site.com/user/Ryan and I want to retreive the domain extension and the username, as to say: http://www.site.(*)/user/(*)

I have two options (afaik) split() or a regexp, split() doesn't really sound too stable (also since the extension could be 'com' or 'com.br', so I'll probably like to use the regexp option, but I have no idea how get started on this one..

1 Answer 1

2
var re = /http:\/\/www.site.([^\/]*)\/user\/(\w*)/
var tokens = 'http://www.site.com.br/user/Ryan'.match(re);
var theWholeUrl = tokens[0];
var domain = tokens[1];
var username = tokens[2];

alert('theWholeUrl: ' + theWholeUrl);
alert('domain: ' + domain);
alert('username: ' + username);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.