In the work need to take the parameters in the URL, a lot, think of writing an expression.
C # version:
String url = "http://url/default.aspx?sname=sd&articleid=76369635-2b9c-495e-a7ec-44bbb290991f&pagenum=2 &magid=156&rtype=next ";
Regex Urlregex = new Regex (?: ^| /?| &) pagenum= ([^&]*) (?: &|$) ");
Match m = urlregex.match (URL. ToLower ());
String pagenum = String. Empty;
if (m.success)
{
Pagenum = m.groups[1]. Value;
}
JS Version (EXT):
function Geturlparam (name) {
var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)");
var r = window.location.search.substr (1). Match (REG);
if (r!=null) {
Return unescape (r[2]);
}
return null;
}
Alert (Geturlparam ("Id"));
If the current URL is http://localhost/test/Untitled-11.html?Id=12456, then the function returns 12456,
Regular expression "(^|&)" + name + "= ([^&]*) (&|$)" is the key to this function
The return value of the function, R[2], represents the second match in the regular expression ([^&]*). Why "([^&]*)" can match 12456.
The [^xyz] negative character set is combined according to the syntax of the regular expression. Matches any characters that are not included. For example, ' [^ABC] ' can match ' P ' in ' plain '. "[^&]*" is 0 or more any character other than "&".