111,126
社区成员
发帖
与我相关
我的任务
分享
string str = @"apple
astute
boomerang
car
donkey
effort
apples
fun "; // 单词库
string[] Key = new string[] {"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz" }; // 键盘按键组
string input = Console.ReadLine();
int count = input.Length;
if (count > 0)
{
string pattern = "^"; // 正则表达式
for (int i = 0; i < count; i++)
{
char c = input[i];
int index = Convert.ToInt32(c.ToString())-2;
pattern += "[" + Key[index] + "]"; // 拼接正则表达式
}
pattern += "[a-z]*"; // 拼接正则表达式
MatchCollection mc = Regex.Matches(str, pattern,RegexOptions.Multiline);
foreach (Match m in mc)
{
Console.WriteLine(m.Value); // 所有符合的结果
}
}
else
{
Console.WriteLine("Input Pls!!");
}