日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#正則表達式之定位字符淺析

C#正則表達式之定位字符都有哪些呢?讓我們來看看:

公司主營業(yè)務:成都做網(wǎng)站、成都網(wǎng)站建設、移動網(wǎng)站開發(fā)等業(yè)務。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)推出青縣免費做網(wǎng)站回饋大家。

“定位字符”所代表的是一個虛的字符,它代表一個位置,你也可以直觀地認為“定位字符”所代表的是某個字符與字符間的那個微小間隙。

^  表示其后的字符必須位于字符串的開始處

$  表示其前面的字符必須位于字符串的結束處

\b  匹配一個單詞的邊界

\B  匹配一個非單詞的邊界

另外,還包括:\A  前面的字符必須位于字符處的開始處,\z  前面的字符必須位于字符串的結束處,\Z  前面的字符必須位于字符串的結束處,或者位于換行符前

下面提供一些簡單的C#正則表達式之定位字符示例:

 
 
  1. string i = "Live for nothing,die for something";  
  2. Regex r1 = new Regex("^Live for nothing,die for something$");  
  3. //r1.IsMatch(i) true  
  4. Regex r2 = new Regex("^Live for nothing,die for some$");  
  5. //r2.IsMatch(i) false  
  6. Regex r3 = new Regex("^Live for nothing,die for some");  
  7. //r3.IsMatch(i) true  
  8.  
  9. string i = @"Live for nothing,  
  10. die for something";//多行  
  11. Regex r1 = new Regex("^Live for nothing,die for something$");  
  12. Console.WriteLine("r1 match count:" + r1.Matches(i).Count);//0  
  13. Regex r2 = new Regex("^Live for nothing,die for something$",  
  14.  RegexOptions.Multiline);  
  15. Console.WriteLine("r2 match count:" + r2.Matches(i).Count);//0  
  16. Regex r3 = new Regex("^Live for nothing,\r\ndie for something$");  
  17. Console.WriteLine("r3 match count:" + r3.Matches(i).Count);//1  
  18. Regex r4 = new Regex("^Live for nothing,$");  
  19. Console.WriteLine("r4 match count:" + r4.Matches(i).Count);//0  
  20. Regex r5 = new Regex("^Live for nothing,$", RegexOptions.Multiline);  
  21. Console.WriteLine("r5 match count:" + r5.Matches(i).Count);//0  
  22. Regex r6 = new Regex("^Live for nothing,\r\n$");  
  23. Console.WriteLine("r6 match count:" + r6.Matches(i).Count);//0  
  24. Regex r7 = new Regex("^Live for nothing,\r\n$", RegexOptions.Multiline);  
  25. Console.WriteLine("r7 match count:" + r7.Matches(i).Count);//0  
  26. Regex r8 = new Regex("^Live for nothing,\r$");  
  27. Console.WriteLine("r8 match count:" + r8.Matches(i).Count);//0  
  28. Regex r9 = new Regex("^Live for nothing,\r$", RegexOptions.Multiline);  
  29. Console.WriteLine("r9 match count:" + r9.Matches(i).Count);//1  
  30. Regex r10 = new Regex("^die for something$");  
  31. Console.WriteLine("r10 match count:" + r10.Matches(i).Count);//0  
  32. Regex r11 = new Regex("^die for something$", RegexOptions.Multiline);  
  33. Console.WriteLine("r11 match count:" + r11.Matches(i).Count);//1  
  34. Regex r12 = new Regex("^");  
  35. Console.WriteLine("r12 match count:" + r12.Matches(i).Count);//1  
  36. Regex r13 = new Regex("$");  
  37. Console.WriteLine("r13 match count:" + r13.Matches(i).Count);//1  
  38. Regex r14 = new Regex("^", RegexOptions.Multiline);  
  39. Console.WriteLine("r14 match count:" + r14.Matches(i).Count);//2  
  40. Regex r15 = new Regex("$", RegexOptions.Multiline);  
  41. Console.WriteLine("r15 match count:" + r15.Matches(i).Count);//2  
  42. Regex r16 = new Regex("^Live for nothing,\r$\n^die for something$",  
  43.  RegexOptions.Multiline);  
  44. Console.WriteLine("r16 match count:" + r16.Matches(i).Count);//1  
  45. //對于一個多行字符串,在設置了Multiline選項之后,^和$將出現(xiàn)多次匹配。  
  46.  
  47. string i = "Live for nothing,die for something";  
  48. string m = "Live for nothing,die for some thing";  
  49. Regex r1 = new Regex(@"\bthing\b");  
  50. Console.WriteLine("r1 match count:" + r1.Matches(i).Count);//0  
  51. Regex r2 = new Regex(@"thing\b");  
  52. Console.WriteLine("r2 match count:" + r2.Matches(i).Count);//2  
  53. Regex r3 = new Regex(@"\bthing\b");  
  54. Console.WriteLine("r3 match count:" + r3.Matches(m).Count);//1  
  55. Regex r4 = new Regex(@"\bfor something\b");  
  56. Console.WriteLine("r4 match count:" + r4.Matches(i).Count);//1  
  57. //\b通常用于約束一個完整的單詞 

C#正則表達式之定位字符使用的基本內(nèi)容就向你介紹到這里,希望對你了解和學習C#正則表達式有所幫助。


分享題目:C#正則表達式之定位字符淺析
網(wǎng)頁URL:http://www.dlmjj.cn/article/dhscdpp.html