Interpreting Regular Expressions in C # (3)

Source: Internet
Author: User
Common expressions

To better understand how to use rules in the C # Environment Expression I have written some rule expressions that may be useful to you. These expressions have been used in other environments and hope to help you .?
??
Roman numerals

String p1 = "^ m * (D? C {0, 3} | C [DM]) "+" (L? X {0, 3} | x [LC]) (V? I {0, 3} | I [VX]) $ ";
??
? String T1 = "VII ";
??
? Match M1 = RegEx. Match (T1, P1 );?
???
Exchange the first two words

String t2 = "The quick brown fox ";
??
? String P2 = @ "(/S + )";
??
? RegEx X2 = new RegEx (P2 );
??
? String r2 = x2.replace (t2, "$3 $2 $1", 1 );
???
Guan jianzi = Value

String T3 = "myval = 3 ";
??
? String P3 = @ "(/W +)/S * =/S * (. *)/S * $ ";
??
? Match m3 = RegEx. Match (T3, P3 );
???
Implement 80 characters per line

String t4 = "********************"
??
? + "******************************"
??
? + "******************************";
??
? String P4 = ". {80 ,}";
??
? Match M4 = RegEx. Match (T4, P4 );
???
Month/day/year hour: minute: Second Time Format

String T5 = "01/01/01 16:10:01 ";
??
? String P5 = @ "(/d +)/(/d +) :(/d + )";
??
? Match M5 = RegEx. Match (T5, P5 );
???
Change directory (applicable only to Windows)

String T6 = @ "C:/Documents and Settings/user1/desktop /";
??
? String R6 = RegEx. Replace ( T6 , @ "// User1 //", @ "// user2 //");
???
Extended 16-bit escape characters

String T7 = "% 41"; // capital
??
? String P7 = "% ([0-9a-fa-f] [0-9a-fa-f])";
??
? String R7 = RegEx. Replace (T7, P7, hexconvert );?
???
Delete comments in C Language (to be improved)

String T8 = @"
??
? /*
??
? * Notes for traditional styles
??
? */
??
? ";
??
? String P8 = @"
??
? // * # Match the delimiters starting with the Annotation
??
? .*? # Matching comments
??
? /*/# Match the end Separator of the comment
??
? ";
??
? String R8 = RegEx. Replace (T8, p8, "", "XS ");?
???
Deletes spaces at the start and end of a string.

String t9a = "leading ";
??
? String p9a = @ "^/S + ";
??
? String r9a = RegEx. Replace (t9a, p9a ,"");
??
? String t9b = "trailing ";
??
? String p9b = @ "/S + $ ";
??
? String r9b = RegEx. Replace (t9b, p9b ,"");?
???
Add character N after character/to make it a real New Line

String t10 = @ "/ntest/N ";
??
? String R10 = RegEx. Replace (T10, @ "// n", "/N ");?
???
Convert IP addresses

String T11 = "55.54.53.52 ";
??
? String P11 = "^" +
??
? @ "([01]? /D/d | 2 [0-4]/d | 25 [0-5])/. "+
??
? @ "([01]? /D/d | 2 [0-4]/d | 25 [0-5])/. "+
??
? @ "([01]? /D/d | 2 [0-4]/d | 25 [0-5])/. "+
??
? @ "([01]? /D/d | 2 [0-4]/d | 25 [0-5]) "+
??
? "$ ";
??
? Match M11 = RegEx. Match (T11, P11 );?
???
Delete the path contained in the file name

String T12 = @ "C:/file.txt ";
??
? String p12 = @ "^ .*//";
??
? String R12 = RegEx. Replace (T12, p12 ,"");?
???
Concatenate rows from multiple strings

String t13 = @ "this is
??
? A split line ";
??
? String P13 = @ "/S */R? /N/S *";
??
? String R13 = RegEx. Replace (t13, P13 ,"");
???
Extract all numbers in the string

String T14 = @"
??
? Test 1
??
? Test 1, 2.3
??
? Test 47
??
? ";
??
? String p14 = @ "(/d + /.? /D * |/./d + )";
??
? Matchcollection mc14 = RegEx. Matches (T14, p14 );?
???
Find all uppercase letters

String T15 = "this is a test of all caps ";
??
? String P15 = @ "(/B [^/Wa-z0-9 _] +/B )";
??
? Matchcollection mc15 = RegEx. Matches (T15, p15 );?
???
Find lowercase words

String T16 = "this is a test of lowercase ";
??
? String p16 = @ "(/B [^/WA-Z0-9 _] +/B )";
??
? Matchcollection mc16 = RegEx. Matches (T16, p16 );?
???
Find the words whose first letter is uppercase.

String t17 = "this is a test of initial caps ";
??
? String P17 = @ "(/B [^/Wa-z0-9 _] [^/WA-Z0-9 _] */B )";
??
? Matchcollection mc17 = RegEx. Matches (t17, P17 );
???
Find links in a simple HTML language

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.