Common expression

xiaoxiao2021-03-06  58

Common expression

In order to better understand how to use rule expressions in the C # environment, I wrote some rules expressions that may be useful to you. These expressions have been used in other environments. I hope to have some to you. help. 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); two words before exchange

String t2 = "the quick brown fox"; string p2 = @ "(/ s ) (/ s )"; regex x2 = new regex (p2); string r2 = x2.replace (T2, "$ 3 $ 2 $ 1 ", 1); Guan Jian = Value

String T3 = "myval = 3"; string p3 = @ "(/ w ) / s * = / s * (. *) / s * $"; match m3 = regex.match (t3, p3); implement each line 80 characters

String T4 = "*******************" "****************************** ******* " " ****************************** "; String P4 =". {80, } "; Match M4 = Regex.match (T4, P4); Month / Day / Years: Score: Second time format

String T5 = "01/01/01 16:10:01"; String P5 = @ "(/ d ) / (/ d ) / (/ d ): (/ d )" ; Match m5 = regex.match (t5, p5); change the directory (only for Windows platform)

String T6 = @ "c: / documents and settings / user1 / desktop /"; string r6 = regex.replace (T6, @ "// user1 ///" @ "// user2 //); extended 16-bit turn Mean

String T7 = "% 41"; // Capital A String P7 = "% ([0-9A-FA-F] [0-9A-FA-F])"; string r7 = regex.replace (T7, P7, HEXCONVERT); Remove annotations in C language (waiting to be improved)

String T8 = @ "/ * * Traditional Note * /"; String P8 = @ "// * # Match the delimiter started by the comment. *? # Match the annotation / * / # matching annotation end delimiter; String r8 = regex.replace (T8, P8, "", "XS"); Delete String T9A = "Leading" in the start and end in the string; string p9a = @ "^ / s "; String R9a = Regex .Replace (T9A, P9A, ""); String T9B = "trailing"; string p9b = @ "/ s $"; string r9b = regex.replace (T9B, P9B, ""); add character n in characters / Make it a true new line

String T10 = @ "/ nteest / n"; string r10 = regex.replace (t10, @ "// n", "/ n"); conversion IP address

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 " @" ([01]? / D / d | 2 [0-4] / d | 25 [0-5]) " " $ "; match m11 = regex .Match (t11, p11); Delete the file name containing the path

String T12 = @ "c: /file.txt"; string p12 = @ "^. * //"; string r12 = regex.replace (t12, p12, ""); links in multi-line strings

String T13 = @ "this is a split line"; string p13 = @ "/ s * / r? / n / s *"; string r13 = regex.replace (T13, P13, ""); extract the string All numbers

String T14 = @ "TEST 1 TEST 2.3 TEST 47"; STRING P14 = @ "(/ D /.? / D * | /. Matchcollection MC14 = Regex.matches (T14, P14); find out Upper case

String T15 = "this is a test of all caps"; string p15 = @ "(/ b)"; matchcollection mc15 = regex.matches (t15, p15); Small write words string t16 = "this is a test of lowercase"; string p16 = @ "(/ b)"; matchcollection mc16 = regex.matches (T16, P16); Find the first letter for 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 simple HTML languages

String T18 = @ " first tag text Next tag text "; String p18 = @" ] *? Href / s * = / s * ["" "" " @" ([^ "">] ?) ['""]? > "; Matchcollection MC18 = Regex.matches (T18, P18," Si ");


New Post(0)