Vikash Vikash - 1 year ago 70
Javascript Question

How to search string between two character in jQuery

I want to search string between two characters in JavaScript, jQuery.

Here id my url"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.

Answer Source

Using match() with capturing group regex

var str = '"artist,m‌​agic".';

var res = str.match(/status=([^&]+)/)[1]


or using split()

var str = '"artist,m‌​agic".';

var res = str.split('status=')[1].split('&')[0];


or using substring() and indexOf()

var str = '"artist,m‌​agic".',
  ind = str.indexOf('status=');

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


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