usingSystem;usingSystem.Collections;usingSystem.Configuration;usingSystem.Data;usingSystem.Linq;usingsystem.web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.HtmlControls;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Xml.Linq;usingSystem.Text.RegularExpressions;namespacetest{ Public Partial classRegexTest:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) { if(!IsPostBack) { //Replace the img tag stringImgreg ="|\\/>)"; stringImgcontent =""; //Create a regularRegex reg =NewRegex (Imgreg); //determine if the imgcontent contains a matching character BOOLIsMatch =Reg. IsMatch (imgcontent); Response.Write (IsMatch+"<br/>"); Response.Write (Imgcontent+"<br/>"); //The result after the replacement stringresult = Reg. Replace (Imgcontent,""); //the content of imgcontent has not changedResponse.Write (Imgcontent +"<br/>"); Response.Write (Result+"<br/>"); Response.Write ("============================= get matching results ========================<br/>"); //Get matching results stringContent ="aaaabbbbCCCC"; stringPxregstr ="px"; Regex Pxreg=NewRegex (Imgreg); //get a matching result array varMatchs =pxreg.matches (content); foreach(varIteminchmatchs) {Response.Write (item+"<br/>"); } Response.Write ("========================= get regular segmentation match result =====================<br/>"); //use regular split contentRegex Splitreg =NewRegex (Imgreg); //get a matching result array varResults =pxreg.split (content); foreach(varIteminchresults) {Response.Write (item+"<br/>"); } } } }}
The use of C # regex regular common methods