如何在jQuery中搜索两个字符之间的字符串

How to search string between two character in jQuery

本文关键字:两个 字符 之间 字符串 jQuery 搜索      更新时间:2023-09-26

我想在JavaScript,jQuery中搜索两个字符之间的字符串。

这里 id 我的网址

http://local.evibe-dash.in/vendors/new?status=Phone&count=60&type="艺术家,魔术"。

我想在"status=" and first &之间搜索字符串,以便当我获得除此值以外的其他值时,我可以输入 URL。

使用 match() 捕获组正则表达式

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);


或使用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);


或使用substring()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);