我需要一个匹配字符串中三个连续字符(任何字母数字字符)的正则表达式。
其中2a82a9e4eee646448db00e3fccabd8c7 “eee”将是一场比赛。
其中 2a82a9e4efe64644448db00e3fccabd8c7 “444”将是一场比赛。
等
答案 0 :(得分:7)
使用反向引用。
([a-zA-Z0-9])\1\1
答案 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*");
}
}