暈死 多做几层判断 if (str.Length > 6 && !str.EndsWith("-")) { if (Regex.IsMatch(str, "[^-][A-Z,-]")) { Console.Write("符合要求"); } } 不以什麽結束我也判斷不來哦
http://download.csdn.net/source/2024655 书名:C#入门经典(第3版)ISBN:9787302127352[十位:7302127352]作者:(美)Karli Watson Christian Nagel出版社:清华大学出版社出版日期:2006年05月页数:864
string[] str = new string[] { "123456","-12","12-","12-22A","a-A-A-1","aa--aa","1234569","-"}; Regex re = new Regex(@"^(?!-)[A-Z0-9-]{5,}[A-Z0-9]$"); foreach (string s in str) { Console.WriteLine(re.Match(s).Value); }
using System; using System.Text.RegularExpressions; namespace Test { class Program { public static void Main(string[] args) { string str = "-98978"; if(Regex.IsMatch(str,@"^[^-]\w{4}[^-]$")) { Console.WriteLine("格式正确"); } Console.ReadKey(true); } } }
^(?!-)[A-Z0-9]{5,}((?!-)[A-Z0-9])$
Regex re = new Regex("[A-Z0-9][A-Z0-9-]{4,}[A-Z0-9]", RegexOptions.None); MatchCollection mc = re.Matches("text"); foreach (Match ma in mc) { }
多做几层判断 if (str.Length > 6 && !str.EndsWith("-"))
{
if (Regex.IsMatch(str, "[^-][A-Z,-]"))
{
Console.Write("符合要求");
}
}
不以什麽結束我也判斷不來哦
书名:C#入门经典(第3版)ISBN:9787302127352[十位:7302127352]作者:(美)Karli Watson Christian Nagel出版社:清华大学出版社出版日期:2006年05月页数:864
foreach (string s in str)
{
Console.WriteLine(re.Match(s).Value);
}
using System.Text.RegularExpressions;
namespace Test
{
class Program
{
public static void Main(string[] args)
{
string str = "-98978";
if(Regex.IsMatch(str,@"^[^-]\w{4}[^-]$"))
{
Console.WriteLine("格式正确");
}
Console.ReadKey(true);
}
}
}
^(?!-)[A-Z0-9]{5,}((?!-)[A-Z0-9])$
MatchCollection mc = re.Matches("text");
foreach (Match ma in mc)
{
}
^[A-Z0-9][A-Z0-9\-]{4,}[A-Z0-9]$看来是来晚了