ASP tutorials. NET C # matching, grouping, and replacing
There is a project cited WebService, because at the same time on several servers, in order to facilitate switching, I will be able to dynamically change its IP (only IP is different, not webservice different), so I just replace the server address part of it can be
2, to extract the desired data from the query string in order to restore the data to the Web page, similar to the ASP.net tutorial viewstate features
private string Testrex (match m)
{
Group 0, which is all matches, followed by the parentheses in each
return m.groups tutorial [1] + "/88.88.88.88:1000" + m.groups[3];
}
protected void Regextest ()
{
Test regular replacement
string s = "http://221.221.221.221:8180/ws/services/n_ophospitaldoctorservice?wsdl";
Replace IP address plus port number for 88.88.88.88:1000
Regex rx = new Regex (@ https?:/) (/[^/]+) (/.*)");
MatchEvaluator me = new MatchEvaluator (Testrex);
s = Rx.replace (S, me);//Method 1, the way of the delegate
s = Rx.replace (S, "$1/88.88.88.88:1000$3"); Method 2, how to replace a string
Not defining 88.88.88.88:1000 as a variable is to make it easier to demonstrate why I've split http://(http:/) and (/221.232.137 ...),
Like the top, if I split it up (https?:/ /), it will be written as Rx.replace (S, "$188.88.88.88:100$3"), and obviously, the $ $88,
This is any case that you need to pay attention to when you represent a group number with $
On the contrary, the use of the above MatchEvaluator does not exist because of the group, not the $
Response.Write (s);
Response.Write ("<br/>");
Gets the date inside the query string
String depselectedsql = "1=1 and Reserve_date>=to_date" (' 2010-10-10 ', ' yyyy-mm-dd ') and Reserve_date<=to_date (' 2010-11-10 ', ' yyyy-mm-dd ');
Regex r = new Regex (@ "reserve_date.=to_date.") (DDDD-DD-DD) ", regexoptions.ignorecase);
MatchCollection mc = r.matches (Depselectedsql);
if (Mc.count < 2)
{
Response.Write ("Invalid query string!");
Return
}
string sdate = Mc[0].groups[1].value;
string edate = Mc[1].groups[1].value;
Response.Write (sdate + "<br/>" + edate);
}