When it comes to C # regular expressions, the title is a bit biased, the regular expression is supported by all languages, not just C #, but the definition of regular expressions is varied and does not achieve different effects:
Basic knowledge of regular expressions:
/****************************************** Common Meta-character ********************************************************/
Code |
Description |
. |
Match any character other than line break |
\w |
Match letters or numbers or underscores or kanji |
\s |
Match any of the whitespace characters |
\d |
Match numbers |
\b |
Match the beginning or end of a word |
^ |
Match the start of a string |
$ |
Match the end of a string |
/******************************************* Common restriction ******************************************************/
Code/Syntax |
Description |
* |
Repeat 0 or more times |
+ |
Repeat one or more times |
? |
Repeat 0 or one time |
N |
Repeat n times |
{N,} |
Repeat N or more times |
{N,m} |
Repeat N to M times
|
/******************************************* commonly used antonyms *******************************************************/
match is not the beginning or end of a word
code/syntax |
description |
\w |
matches any characters that are not letters, numbers, underscores, kanji |
\s |
|
\d< /span> |
matches any non-numeric character |
\b |
[^x] |
matches any character except x |
[^aeiou] |
matches any character except aeiou these letters |
/****************************************** Practical Code Reference ********************************************************/
Common function points for regular expressions:
1, matching elements grab the desired results, generally used for data collection and web analysis;
2, data validation;
Simple examples of the use of regular expressions:
Code implementation Function Description:
Verify that the user input data format is: 23:15-23:00 or 23:15-23:00;23:15-23:00;23:15-23:00 data format
The code is as follows: (regular expression is the focus)
Static voidMain (string[] args) {MatchCollection Martcollcect=NewRegex (@"(^\d{2}:\d{2}-\d{2}:\d{2};$)"). Matches ("23:15-25:16;23:15-25:16;23:15-25:16"); BOOLResultbook = Regexchecktime ("23:15-25:16;23:15-25:16;23:15-25:16"); Resultbook= Regexchecktime ("23:15-23:16;as:15-23:16;23:15-23:16"); Resultbook= Regexchecktime ("23:15-23:16;23:15-23:16;23:15-22:16"); Resultbook= Regexchecktime ("23:15-23:16"); } /// <summary> ///The validation time format is: 23:15-25:16;03:15-25:16 mode/// </summary> /// <param name= "Inputcontext" ></param> /// <returns></returns> Public Static BOOLRegexchecktime (stringInputcontext) { stringRegparm =@"^ ([[0-1]\d|2[0-3]):([0-5]\d]-([0-1]\d|2[0-3]):([0-5]\d];) * ([0-1]\d|2[0-3]):([0-5]\d]-([0-1]\d|2[0-3]):([ 0-5]\d) $"; Regex RG=NewRegex (regparm); returnRG. IsMatch (Inputcontext); }
Regular reference syntax:
Http://www.cnblogs.com/youring2/archive/2009/11/07/1597786.html
C # Regular Expressions