string regg = @"^[^\\/:\*\?""<>|]{1,120}$"; if (!Regex.IsMatch(command.NewName, regg)) { Console.WriteLine("不合法"); } else { Console.WriteLine("合法"); }