求一个正则表达式~

昵称90天内修改一次 2013-07-31 01:26:44
要求是这样的
例如:2.0L 或 2.0l
验证字符串
就是decimal(2,1)后面加上一个大写的或小写的L
...全文
120 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
q107770540 2013-07-31
  • 打赏
  • 举报
回复
引用 6 楼 foggy2330 的回复:
[quote=引用 3 楼 q107770540 的回复:]
Regex.IsMatch(str,@"^(?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();
抛异常了 正在分析“^(?i)\d+(\.\d+)?l)$”- ) 过多。[/quote] SORRY,多了个括号:
Regex.IsMatch(str,@"^\d+(\.\d)?[lL]$");
EnForGrass 2013-07-31
  • 打赏
  • 举报
回复
\d+(\.\d)?(?:l|L)?
非我莫属One 2013-07-31
  • 打赏
  • 举报
回复

            string str = "22.4L";
            bool b4 = Regex.IsMatch(str, @"^([0-9]{1})\.\d(l|L)$");
            Console.WriteLine(b4);
可以了,试一试
缭绕飘渺 2013-07-31
  • 打赏
  • 举报
回复
那就是两维数字和一个点,然后一个L啊 自己拿个正则验证工具,最多三分钟搞定
  • 打赏
  • 举报
回复
规则就是 符合decimal(2,1)后面加上一个大写的或小写的L
  • 打赏
  • 举报
回复
引用 8 楼 sjyforg 的回复:
打错,应该是\d\.\d(l|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)$");
            bool b4 = Regex.IsMatch(str, @"\d\.\d(l|L)");
            //Console.WriteLine(b1);
            //Console.WriteLine(b2);
            //Console.WriteLine(b3);
            Console.WriteLine(b4);
你这个也返回true
申江渔夫 2013-07-31
  • 打赏
  • 举报
回复
打错,应该是\d\.\d(l|L)
申江渔夫 2013-07-31
  • 打赏
  • 举报
回复
\d\.\d[l|L]
  • 打赏
  • 举报
回复
引用 3 楼 q107770540 的回复:
Regex.IsMatch(str,@"^(?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();
抛异常了 正在分析“^(?i)\d+(\.\d+)?l)$”- ) 过多。
  • 打赏
  • 举报
回复
引用 2 楼 bdmh 的回复:

            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);
            }
            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
  • 打赏
  • 举报
回复
引用 1 楼 Chinajiyong 的回复:
\d+(\.\d+)?(?:l|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
q107770540 2013-07-31
  • 打赏
  • 举报
回复
Regex.IsMatch(str,@"^(?i)\d+(\.\d+)?l)$");
bdmh 2013-07-31
  • 打赏
  • 举报
回复

            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);
            }
EnForGrass 2013-07-31
  • 打赏
  • 举报
回复
\d+(\.\d+)?(?:l|L)?

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧