- .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 = ".";
Regex rg = new Regex(regularExpression);
string contents = "012abc!@#%&&_-\t";
for (int i = 0; i < contents.Length; i++)
{
if (rg.IsMatch(contents[i].ToString()))
{
Console.WriteLine(contents[i] + "成功");
}
else
{
Console.WriteLine(contents[i] + "不成功");
}
}
string test = "\n";
if (rg.IsMatch(test))
{
Console.WriteLine("回车符合正则表达式");
}
else
{
Console.WriteLine("回车不符合正则表达式");
}
Console.ReadKey();
}
}
}
result
0成功
1成功
2成功
a成功
b成功
c成功
!成功
@成功
#成功
%成功
&成功
&成功
_成功
-成功
成功
回车不符合正则表达式
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