url地址栏参数
public string getUrlPara(string sUrl, string paraName)
{
string sReg = "(?:\\?|&){1}" + paraName + "=([^&]*)";
System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(sReg,
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
return re.Match(sUrl).Groups[1].Value;
}
/// <summary> /// 获取Url /// </summary> /// <param name="name"></param> /// <param name="value"></param> /// <returns></returns> protected string getUrl(string name, string value) { string url = System.Text.RegularExpressions.Regex.Replace(Request.Url.Query.Trim(), @"^\?", ""); url = System.Text.RegularExpressions.Regex.Replace(url, "^" + name + "=.*?&|" + name + "=.*?&", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); url = System.Text.RegularExpressions.Regex.Replace(url, "&{0,1}" + name + "=.*", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); url = System.Text.RegularExpressions.Regex.Replace(url, "^page=.*?&|page=.*?&", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); url = System.Text.RegularExpressions.Regex.Replace(url, "&{0,1}page=.*", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); if (url.Trim() == "") { return "?" + name + "=" + value; } return getReplaceUrl("?" + name + "=" + value + "&" + url, "key"); } /// <summary> /// 获取Url /// </summary> /// <param name="name"></param> /// <param name="value"></param> /// <returns></returns> protected string getReplaceUrl(string url, string name) { url = System.Text.RegularExpressions.Regex.Replace(url, "^" + name + "=.*?&|" + name + "=.*?&", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); url = System.Text.RegularExpressions.Regex.Replace(url, "&{0,1}" + name + "=.*", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); url = System.Text.RegularExpressions.Regex.Replace(url, "^page=.*?&|page=.*?&", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); url = System.Text.RegularExpressions.Regex.Replace(url, "&{0,1}page=.*", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); return url; }
function getUrlPara(paraName) { var sUrl = location.href; var sReg = "(?:\\?|&){1}" + paraName + "=([^&]*)" var re = new RegExp(sReg, "gi"); re.exec(sUrl); return RegExp.$1; } function getUrl(name, value) { var _cpath = window.location.href; var _css = _cpath.indexOf('?'); var url = ""; if (_css > -1) { url = _cpath.substring(_css + 1); } var sReg1 = "^" + name + "=.*?&|" + name + "=.*?&"; var re1 = new RegExp(sReg1, "gi"); url = url.replace(re1, ""); var sReg2 = "&{0,1}" + name + "=.*"; var re2 = new RegExp(sReg2, "gi"); url = url.replace(re2, ""); var sReg3 = "^page=.*?&|page=.*?&"; var re3 = new RegExp(sReg3, "gi"); url = url.replace(re3, ""); var sReg4 = "&{0,1}page=.*"; var re4 = new RegExp(sReg4, "gi"); url = url.replace(re4, ""); if ($.trim(url).length < 1) { return "?" + name + "=" + value; } return getReplaceUrl("?" + name + "=" + value + "&" + url, "key"); } function getReplaceUrl(url, name) { var sReg1 = "^" + name + "=.*?&|" + name + "=.*?&"; var re1 = new RegExp(sReg1, "gi"); url = url.replace(re1, ""); var sReg2 = "&{0,1}" + name + "=.*"; var re2 = new RegExp(sReg2, "gi"); url = url.replace(re2, ""); var sReg3 = "^page=.*?&|page=.*?&"; var re3 = new RegExp(sReg3, "gi"); url = url.replace(re3, ""); var sReg4 = "&{0,1}page=.*"; var re4 = new RegExp(sReg4, "gi"); url = url.replace(re4, ""); return url; }
string str = QConnectSDK.CustomWebRequest.getResponse("http://www.baidu.com/", QConnectSDK.Method.GET, null);
Regex reg = new Regex("<a\\s+href\\s*=\\s*\"?(.*?)[\"|>]", RegexOptions.IgnoreCase);
MatchCollection mats = reg.Matches(str);
string aa = "";
foreach (Match mat in mats)
{
aa += mat.Groups[1].Value + "<br />";
}
Response.Write(aa);