0

How do I remove everything before /post in this string below and add my own address using Javascript/JQuery

showLogo=false&showVersionInfo=false&dataFile=/post/2653785385/photoset_xml/tumblr_lepsihc2RV1qbclqg/500

I want it to appear like this:

http://mydomain.com/post/2653785385/photoset_xml/tumblr_lepsihc2RV1qbclqg/500

2 Answers 2

3
var str = 'showLogo=false&showVersionInfo=false&dataFile=/post/2653785385/photoset_xml/tumblr_lepsihc2RV1qbclqg/500';

str = 'http://mydomain.com' + str.split('&dataFile=')[1];

Example: http://jsfiddle.net/52z2z/

Here it splits the string on '&dataFile=', gets the last item in the resulting Array, and concatenates it do your domain.

1

You could also do this in Javascript using regular expressions:

var url = "showLogo=false&showVersionInfo=false&dataFile=/post/2653785385/photoset_xml/tumblr_lepsihc2RV1qbclqg/500";
var matches = url.match(/dataFile=(.*)/);
var what_you_need = "http://mydomain.com" + matches[1];

HTH

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.