国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Regex > 正文

比較不錯的C#中的常用的正則表達式

2020-03-16 21:20:38
字體:
來源:轉載
供稿:網友

為了能夠更好地理解如何在C#環境中使用正則表達式,我寫出一些對你來說可能有用的正則表達式,這些表達式在其他的環境中都被使用過,希望能夠對你有所幫助。

羅馬數字

stringp1="^m*(d?c{0,3}|c[dm])"+"(l?x{0,3}|x[lc])(v?i{0,3}|i[vx])$";

stringt1="vii";

Matchm1=Regex.Match(t1,p1);

交換前二個單詞

stringt2="thequickbrownfox";

stringp2=@"(/S+)(/s+)(/S+)";

Regexx2=newRegex(p2);

stringr2=x2.Replace(t2,"$3$2$1",1);

關健字=值

stringt3="myval=3";

stringp3=@"(/w+)/s*=/s*(.*)/s*$";

Matchm3=Regex.Match(t3,p3);

實現每行80個字符

stringt4="********************"

+"******************************"

+"******************************";

stringp4=".{80,}";

Matchm4=Regex.Match(t4,p4);

月/日/年小時:分:秒的時間格式

stringt5="01/01/0116:10:01";

stringp5=@"(/d+)/(/d+)/(/d+)(/d+):(/d+):(/d+)";

Matchm5=Regex.Match(t5,p5);

改變目錄(僅適用于Windows平臺)

stringt6=@"C:/DocumentsandSettings/user1/Desktop/";

stringr6=Regex.Replace(t6,@"//user1//",@"//user2//");

擴展16位轉義符

stringt7="%41";//capitalA

stringp7="%([0-9A-Fa-f][0-9A-Fa-f])";

stringr7=Regex.Replace(t7,p7,HexConvert);

刪除C語言中的注釋(有待完善)

stringt8=@"

/*

*傳統風格的注釋

*/

";

stringp8=@"

//*#匹配注釋開始的定界符

.*?#匹配注釋

/*/#匹配注釋結束定界符

";

stringr8=Regex.Replace(t8,p8,"","xs");

刪除字符串中開始和結束處的空格

stringt9a="leading";

stringp9a=@"^/s+";

stringr9a=Regex.Replace(t9a,p9a,"");

stringt9b="trailing";

stringp9b=@"/s+$";

stringr9b=Regex.Replace(t9b,p9b,"");

在字符/后添加字符n,使之成為真正的新行

stringt10=@"/ntest/n";

stringr10=Regex.Replace(t10,@"//n","/n");

轉換IP地址

stringt11="55.54.53.52";

stringp11="^"+

@"([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])"+

"$";

Matchm11=Regex.Match(t11,p11);

刪除文件名包含的路徑

stringt12=@"c:/file.txt";

stringp12=@"^.*//";

stringr12=Regex.Replace(t12,p12,"");

聯接多行字符串中的行

stringt13=@"thisis

asplitline";

stringp13=@"/s*/r?/n/s*";

stringr13=Regex.Replace(t13,p13,"");

提取字符串中的所有數字

stringt14=@"

test1

test2.3

test47

";

stringp14=@"(/d+/.?/d*|/./d+)";

MatchCollectionmc14=Regex.Matches(t14,p14);

找出所有的大寫字母

stringt15="ThisISaTestOFALLCaps";

stringp15=@"(/b[^/Wa-z0-9_]+/b)";

MatchCollectionmc15=Regex.Matches(t15,p15);

找出小寫的單詞

stringt16="ThisisATestoflowercase";

stringp16=@"(/b[^/WA-Z0-9_]+/b)";

MatchCollectionmc16=Regex.Matches(t16,p16);

找出第一個字母為大寫的單詞

stringt17="ThisisATestofInitialCaps";

stringp17=@"(/b[^/Wa-z0-9_][^/WA-Z0-9_]*/b)";

MatchCollectionmc17=Regex.Matches(t17,p17);

找出簡單的HTML語言中的鏈接

stringt18=@"

 

firsttagtext

nexttagtext

 

";

stringp18=@"]*?HREF/s*=/s*[""']?"+@"([^'"">]+?)['""]?>";

MatchCollectionmc18=Regex.Matches(t18,p18,"si");

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 咸阳市| 虹口区| 津南区| 呼和浩特市| 兴义市| 汝南县| 那曲县| 弋阳县| 黄大仙区| 兰考县| 左贡县| 梨树县| 米脂县| 元阳县| 铁岭市| 涞源县| 松江区| 安吉县| 台州市| 沽源县| 柳州市| 北安市| 镇安县| 娄底市| 封丘县| 安宁市| 通榆县| 抚顺市| 洛南县| 明星| 曲阜市| 鱼台县| 鹰潭市| 钟祥市| 乐安县| 栖霞市| 肥城市| 泽州县| 华蓥市| 虞城县| 东至县|