- .NET Framework : 4.7.2
- IDE : Visual Studio Community 2019
- OS : Windows 10 x64
- typesetting : Markdown
- blog : xinshaopu.blog.csdn.net
code
using System;
using System.Text.RegularExpressions;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
string regularExpression = "[0-9]{3}";
Regex rg = new Regex(regularExpression);
string[] contents = { "12", "123aa", "a3bb12345", "a3bb123456" };
for (int i = 0; i < contents.Length; i++)
{
if (rg.IsMatch(contents[i]))
{
Console.WriteLine(contents[i] + "成功");
}
else
{
Console.WriteLine(contents[i] + "不成功");
}
}
Console.ReadKey();
}
}
}
result
12不成功
123aa成功
a3bb12345成功
a3bb123456成功
resource
- [文档] docs.microsoft.com/zh-cn/dotnet/csharp
- [规范] github.com/dotnet/docs/tree/master/docs/standard/design-guidelines
- [平台] regexr.com
- [文档] www.runoob.com/regexp/regexp-tutorial.html
- [源码] referencesource.microsoft.com
- [ IDE ] visualstudio.microsoft.com/zh-hans
- [.NET Core] dotnet.github.io