C#正则表达式,匹配小数

*匹配上一个元素零次或多次

\+转义后为‘+’

\-转义后为‘-’,匹配负数

\d一个数字

\d*零个或多个数字

\.一个点,点前加\是为了转义,如果不转义的话,一个点代表一个通配符,也就是任意一个字符都会被匹配,所以此处只匹配小数点要加\

\d{2}匹配两个数字

string strstr = "insert into stu(name,password) values('3.33','123.99')";

 string pipei3 = @"\+*\-*\d*\.\d{2}";

foreach (Match pi in Regex.Matches(strstr, pipei3))
            { 
               
                Console.WriteLine("匹配到:"+pi.Value); 
            

            }

 Console.ReadKey();

猜你喜欢

转载自blog.csdn.net/qq_36045385/article/details/80882669
今日推荐