zoukankan      html  css  js  c++  java
  • 一个可以匹配整数、浮点数的正则表达式

    //正则表达式

    string regStr =  "^[+-]?([0-9]*\.?[0-9]+|[0-9]+\.?[0-9]*)([eE][+-]?[0-9]+)?$";

    Description
    A regular expression that matches numbers. Integers or decimal numbers with or without the exponential form.
    Matches
    23 | -17.e23 | +.23e+2
    Non-Matches
    +.e2 | 23.17.5 | 10e2.0

    验证方法如下:

    View Code
     1 /// <summary>
     2         /// 验证输入字符串为数字
     3         /// </summary>
     4         /// <param name="str">输入字符</param>
     5         /// <returns>返回一个bool类型的值</returns>
     6         private static bool IsNumeric(string str)
     7         {
     8             System.Text.RegularExpressions.Regex reg1
     9                 = new System.Text.RegularExpressions.Regex(@"^[+-]?([0-9]*\.?[0-9]+|[0-9]+\.?[0-9]*)([eE][+-]?[0-9]+)?$");
    10             if (str != "")
    11             {
    12                 return reg1.IsMatch(str);
    13             }
    14             else
    15             {
    16                 return true;
    17             }
    18         } 
  • 相关阅读:
    【ZJOI2017】树状数组
    【ZJOI2014】力
    【WC2017】挑战
    kube event 事件监控
    k8s nginx-ingress 504 timeout
    k8s 工具集
    jvm 性能调优工具之 jmap
    Elasticsearch unassigned 故障排查
    harbor API 与tag 清理
    前后端分离文档
  • 原文地址:https://www.cnblogs.com/ZHF/p/2564009.html
Copyright © 2011-2022 走看看