Alex Alex - 7 months ago 25
jQuery Question

jQuery/JS extract a specific string from URL

I have the following URL:

I only need to extract Rome from the url. So far I have managed to do this:

var citySearch = $.cookie('recentSearch');

where citySearch the url.

This only returns "Rome%2C+Italy&country=Italy&city=Rome&date_from=2016-07-02&date_to=2016-07-05


your regex is matching too much, it should work with:

var citySearch = $.cookie('recentSearch');

This would give you "Rome%2C+Italy" which is the keyword parameter.

hope this helps