zoukankan      html  css  js  c++  java
  • 常用的正則表達式

    ^(0*100{1,1}\.?((?<=\.)0*)?%?$)|(^0*\d{0,2}\.?((?<=\.)\d*)?%?)$

    Description: Percentage (From 0 to 100)
    Matches: 100%|||100|||52.65%
    Non-Matches: -1|||-1%|||100.1%


    Expression: (?!^0*$)(?!^0*\.0*$)^\d{1,5}(\.\d{1,2})?$
     
    Description: validates to 5 digits and 2 decimal places but not allowing zero
    Matches: 12345.12|||0.5
    Non-Matches: 123456.12|||1.234|||.1

     Expression: ^\d$
     
    Description: Matches exactly 1 numeric digit (0-9).
    Matches: 1|||2|||3
    Non-Matches: a|||324|||num

    Expression: ^\d+$
     
    Description: Positive integer value.
    Matches: 123|||10|||54
    Non-Matches: -54|||54.234|||abc

    Expression: ^[-]?([1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|\.[0-9]{1,2})$
     
    Description: This regular expression will match on a real / decimal / floating point / numeric string with no more than 2 digits past the decimal. The negative sign (-) is allowed. No leading zeroes or commas. It is based on a currency regular expression by Tom Persing.
    Matches: 123|||123.54|||-.54
    Non-Matches: 123.543|||0012|||1,000.12


    Expression: ^(0*100{1,1}\.?((?<=\.)0*)?%?$)|(^0*\d{0,2}\.?((?<=\.)\d*)?%?)$
     
    Description: Percentage (From 0 to 100)
    Matches: 100%|||100|||52.65%
    Non-Matches: -1|||-1%|||100.1%


    Expression: ^\d+(?:\.\d{0,2})?$
     
    Description: Matches positive whole numbers with exactly zero or two decimal points if a . is present. Useful for checking currency amounts, such 5 or 5.00 or 5.25. 
    Matches: 1|||1.23|||1234.45
    Non-Matches: a1.34|||1.23a|||a


    Expression: ^((\d{1,2})?([.][\d]{1,2})?){1}[%]{1}$
     
    Description: for checking a value is between 99.99% and 00.00%
    Matches: 99.99%|||9%|||.09%
    Non-Matches: 99|||9.%

    Expression: ^([1-9]|[1-9]\d|100)$
     
    Description: This pattern matches whole numbers 1-100. 
    Matches: 1|||50|||100
    Non-Matches: 0|||.5|||101


    Expression: (^[0]{1}$|^[-]?[1-9]{1}\d*$)
     
    Description: This is a regular expression I used to validate negative and positive WHOLE numbers, including 0.
    Matches: 0|||123|||-123
    Non-Matches: 001|||-012|||-002


    Expression: ^[-+]?[0-9]\d{0,2}(\.\d{1,2})?%?$
     
    Description: Required and regular expression validator. For supporting -999.99 to +999.99 . Positive and Negative integer/ decimal validations. Percentage sign is also supported. Will not allow empty strings. Can increase/decrease the range as you need.
    Matches: 12.3|||123|||-123.45
    Non-Matches: -|||10.1234|||-1234
     


    Expression: ^-?[0-9]{0,2}(\.[0-9]{1,2})?$|^-?(100)(\.[0]{1,2})?$
     
    Description: Matches a negative or positive percentage between 0 and 100 (inclusive). Accepts up to 2 decimal places.
    Matches: 12.34|||100.00|||-2.1
    Non-Matches: 101.1|||10.123|||100.10

    ======================================================================

    Expression: ^(([1-9]{1})|([0-1][0-9])|([1-2][0-3])):([0-5][0-9])$
     
    Description: Matches 24 hour time format.
    Matches: 00:00|||23:59|||10:10
    Non-Matches: 24:00|||00:60|||25:61

    Expression: ^(([1-9]{1})|([0-1][1-2])|(0[1-9])|([1][0-2])):([0-5][0-9])(([aA])|([pP]))[mM]$
     
    Description: Matches 12 hour time format
    Matches: 1:00Am|||12:59pM|||05:05pm
    Non-Matches: 00:00am|||05:60pm|||1:00
     


    Expression: ^(?=\d)(?:(?!(?:1582(?:\.|-|\/)10(?:\.|-|\/)(?:0?[5-9]|1[0-4]))|(?:1752(?:\.|-|\/)0?9(?:\.|-|\/)(?:0?[3-9]|1[0-3])))(?=(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:\d\d)(?:[02468][048]|[13579][26]))\D0?2\D29)|(?:\d{4}\D(?!(?:0?[2469]|11)\D31)(?!0?2(?:\.|-|\/)(?:29|30))))(\d{4})([-\/.])(0?\d|1[012])\2((?!00)[012]?\d|3[01])(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$
     
    Description: yyyy/mm/dd hh:MM:ss Datetime for all AD years, including leap years. Javascript safe version of http://regexlib.com/REDetails.aspx?regexp_id=760. Please see that regex for details of what is being checked
    Matches: 0008-02-29|||2:34:59 PM|||9999/12/31 11:59 PM
    Non-Matches: 04/04/04|||1:00|||1999/1/32

  • 相关阅读:
    【3.5】类和实例属性的查找顺序--mro查找
    【3.4】类变量和实例变量
    【3.3】isinstance和type的区别
    【3.2】抽象基类(abc模块)
    【3.1】鸭子类型和多态
    学习笔记 | 浅谈虚拟函数(Virtual Function)
    学习笔记 | Udacity CarND Term 1: Computer Vision and Deep Learning
    命令行 | File Compression in Linux
    Python: if else in a list comprehension
    Topic | Hyperparameter Optimization for Neural Networks
  • 原文地址:https://www.cnblogs.com/zfq308/p/554426.html
Copyright © 2011-2022 走看看