Reputation: 3551
I want to search string between two characters in JavaScript, jQuery.
Here id my url
http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type="artist,magic".
I want to search string between "status=" and first &
, so that when I will get other value than this, then I can put in URL.
Upvotes: 1
Views: 98
Reputation: 115212
Using match()
with capturing group regex
var str = 'http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type="artist,magic".';
var res = str.match(/status=([^&]+)/)[1]
document.write(res);
or using split()
var str = 'http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type="artist,magic".';
var res = str.split('status=')[1].split('&')[0];
document.write(res);
or using substring()
and indexOf()
var str = 'http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type="artist,magic".',
ind = str.indexOf('status=');
var res = str.substring(ind + 7, str.indexOf('&', ind));
document.write(res);
Upvotes: 1