[英].NET Regular Expression for N number of Consecutive Characters
我需要一個匹配字符串中三個連續字符(任何字母數字字符)的正則表達式。
其中2a82a9e4eee646448db00e3fccabd8c7“eee”將匹配。
其中2a82a9e4efe64644448db00e3fccabd8c7“444”將匹配。
等等
使用反向引用。
([a-zA-Z0-9])\1\1
嘗試這個:
using System;
using System.Text.RegularExpressions;
class MainClass {
private static void DisplayMatches(string text,
string regularExpressionString)
{
Console.WriteLine("using the following regular expression: "
+regularExpressionString);
MatchCollection myMatchCollection =
Regex.Matches(text, regularExpressionString);
foreach (Match myMatch in myMatchCollection) {
Console.WriteLine(myMatch);
}
}
public static void Main()
{
string text ="Missisipli Kerrisdale she";
Console.WriteLine("Matching words that that contain "
+ "two consecutive identical characters");
DisplayMatches(text, @"\S*(.)\1\S*");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.