1, IsMatch () method, the IsMatch () method is actually a return bool worthwhile method, if the test character satisfies the regular expression return true otherwise returns false.
Example:
Match the regular expression, minus @ does not affect the effect of the regex r = new Regex (@ "^[0-9]");//start matching match m = R.match (This.textBox1.Text); while (m.success) { MessageBox.Show ("The first is the number"); return;}
Detects the value entered in the TextBox1, the first is not a number.
Small bet
1, IsMatch () method; the IsMatch () method is actually a return bool-worthy method, if the test character satisfies the regular expression return true otherwise returns false.
2. The @ symbol is used to output the @ "", and the contents of the middle of the two quotes are output as-is, regardless of the special symbol.
2, replace () method, the Replace () method is actually a replacement method, replacing the matching regular expression matching pattern.
Example:
Using system;using system.collections.generic;using system.linq;using system.text;using System.text.regularexpressions;namespace testregularexpressions{ class program { static void Main ( String[] args) { string regulartext = "\\w{1,}@\\w{1,}\\."; String groupemail = "111@126.com"; if (Regex.IsMatch (groupemail,regulartext)) { Console.WriteLine (Regex.Replace (Groupemail, "@", "= = =")); } Else { Console.WriteLine ("Not matched successfully! "); } Console.readkey ();}}}
Output:
3, Split () method, Split () method is actually a split method, according to the matching regular expression of the split stored in the string array.
Example:
Using system;using system.collections.generic;using system.linq;using system.text;using System.text.regularexpressions;namespace testregularexpressions{ class program { static void Main ( String[] args) { string regulartext = ";"; String groupemail = "111@126.com;222@126.com;333@126.com;444@126.com;"; String[] Email; Email = Regex.Split (Groupemail, regulartext); foreach (String personemail in Email) { Console.WriteLine (personemail); } Console.readkey ();}}}
Output:
Small bet
You can use the String.Split method for the string, which is the same effect. For example, to remove the vsnt in English, the code is as follows:
String[] Au=vsnt.split (', ');
Function specifics: Click to open link
Split function Small Package:
#region split the string according to pattern///<summary>// split string by pattern///</summary>// <param Name= "Input" > string to Split </param>// <param name= "pattern" > Split identifier </param>/// <returns > Split array </returns> private string[] splitstring (string input, string pattern) { string[] Email; Email = Regex.Split (input, pattern); return Email; } #endregion
The above is the regular expression regex class common methods of content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!