Vikash
Vikash

Reputation: 3551

How to search string between two character in jQuery

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

Answers (1)

Pranav C Balan
Pranav C Balan

Reputation: 115212

Using match() with capturing group regex

var str = 'http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type="artist,m‌​agic".';

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,m‌​agic".';

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,m‌​agic".',
  ind = str.indexOf('status=');

var res = str.substring(ind + 7, str.indexOf('&', ind));

document.write(res);

Upvotes: 1

Related Questions