我编译了代码:
namespace TestRegExp
{
class Program
{
static void Main(string[] args)
{
if (Regex.IsMatch(args[1], args[0]))
Console.WriteLine("Input matches regular expression.");
else
Console.WriteLine("Input DOES NOT match regular expression.");
}
}
}
当我运行时:
TestRegExp.exe ^a\d{5}$ a12345
节目Input matches regular expression.
TestRegExp.exe ^a\d{5}$ aa12345
节目Input matches regular expression.
TestRegExp.exe ^^a\d{5}$ a12345
节目Input matches regular expression.
TestRegExp.exe ^^a\d{5}$ aa12345
节目Input DOES NOT match regular expression.
为什么显示第二个选项Input matches regular expression.
?
'^' 符号代表字符串 init... 好吗?为什么我必须重复这个?