Alex Alex - 1 year ago 90
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download