我试图学习正则表达式,因为我有一些比其他方式更适合我执行此任务的东西,但是最难理解如何为它编写有效的表达式/模式。
最终目标是验证一个格式为XXXXXX-XXXXXX-XXXXXX的字符串,其中X可以是任何字母数字字符(az AZ 0-9)所以我决定做一些小事只是为了让我的头脑周围如何但仍然失败。
到目前为止,我已经写了这个
string pattern = @"^[a-zA-Z]-[a-zA-Z]$";
string input = "Hello There_3456";
string input2 = "Hello-there";
string input3 = "Hello_there";
Console.WriteLine(Regex.IsMatch(input, pattern));
Console.WriteLine(Regex.IsMatch(input2, pattern));
Console.WriteLine(Regex.IsMatch(input3, pattern));
Console.ReadKey();
我期待虚假,真实,虚假,但所有人都回归为假
我在网上查询的所有内容要么完全要求你知道wtf正则表达式是什么意思,要么给你一个备忘单,然后继续让你知道如何使用它。
如果某人对我这么愚蠢,这将是非常有帮助的