110,502
社区成员
发帖
与我相关
我的任务
分享
string str = "22.4L";
//bool b1 = Regex.IsMatch(str, @"\d+(\.\d+)?(?:l|L)?");
//bool b2 = Regex.IsMatch(str, @"(?is)[\d]\.[\d]l");
bool b3 = Regex.IsMatch(str, @"^(?i)\d+(\.\d+)?l)$");
//Console.WriteLine(b1);
//Console.WriteLine(b2);
Console.WriteLine(b3);
Console.ReadKey();
抛异常了 正在分析“^(?i)\d+(\.\d+)?l)$”- ) 过多。[/quote]
SORRY,多了个括号:
Regex.IsMatch(str,@"^\d+(\.\d)?[lL]$");
string str = "22.4L";
bool b4 = Regex.IsMatch(str, @"^([0-9]{1})\.\d(l|L)$");
Console.WriteLine(b4);
可以了,试一试 string str = "22.4L";
//bool b1 = Regex.IsMatch(str, @"\d+(\.\d+)?(?:l|L)?");
//bool b2 = Regex.IsMatch(str, @"(?is)[\d]\.[\d]l");
//bool b3 = Regex.IsMatch(str, @"^(?i)\d+(\.\d+)?l)$");
bool b4 = Regex.IsMatch(str, @"\d\.\d(l|L)");
//Console.WriteLine(b1);
//Console.WriteLine(b2);
//Console.WriteLine(b3);
Console.WriteLine(b4);
你这个也返回true string str = "22.4L";
//bool b1 = Regex.IsMatch(str, @"\d+(\.\d+)?(?:l|L)?");
//bool b2 = Regex.IsMatch(str, @"(?is)[\d]\.[\d]l");
bool b3 = Regex.IsMatch(str, @"^(?i)\d+(\.\d+)?l)$");
//Console.WriteLine(b1);
//Console.WriteLine(b2);
Console.WriteLine(b3);
Console.ReadKey();
抛异常了 正在分析“^(?i)\d+(\.\d+)?l)$”- ) 过多。 string str = "22.4L";
//bool b1 = Regex.IsMatch(str, @"\d+(\.\d+)?(?:l|L)?");
bool b2 = Regex.IsMatch(str, @"(?is)[\d]\.[\d]l");
//bool b3 = Regex.IsMatch(str, @"^(?i)\d+(\.\d+)?l)$");
//Console.WriteLine(b1);
Console.WriteLine(b2);
//Console.WriteLine(b3);
Console.ReadKey();
22.4L 是错误数据 应该是false string str = "22.4L";
bool b1 = Regex.IsMatch(str, @"\d+(\.\d+)?(?:l|L)?");
//bool b2 = Regex.IsMatch(str, @"(?is)[\d]\.[\d]l");
//bool b3 = Regex.IsMatch(str, @"^(?i)\d+(\.\d+)?l)$");
Console.WriteLine(b1);
//Console.WriteLine(b2);
//Console.WriteLine(b3);
Console.ReadKey();
22.4L 是错误数据 应该是falseRegex.IsMatch(str,@"^(?i)\d+(\.\d+)?l)$");
string str = @"2.0L2.0l";
string strmatch = @"(?is)[\d]\.[\d]l";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(strmatch);
System.Text.RegularExpressions.MatchCollection mc = reg.Matches(str);
foreach (System.Text.RegularExpressions.Match mm in mc)
{
MessageBox.Show(mm.Value);
}