RegEx to match comma separated numbers with optional decimal part

前端 未结 4 392
名媛妹妹
名媛妹妹 2020-11-30 13:16

I\'ve a regex that matches comma separated numbers with an optional two digit decimal part in a given multiline text.

/(?<=\\s|^)\\d{1,3}(,\\d{3})*(\\.\\d         


        
4条回答
  •  暖寄归人
    2020-11-30 13:30

    /(?<=\s|^)(\d{1,3}(,\d{3})*(\.\d{2})?|\.(\d{2}))(?=\s|$)/m
    

    Or taking into account some countries where . is used as a thousand seperator, and , is used as a decimal seperator

    /(?<=\s|^)(\d{1,3}(,\d{3})*(\.\d{2})?|\d{1,3}(\.\d{3})*(,\d{2})?|\.(\d{2})|,(\d{2}))(?=\s|$)/m
    

    Insane Regex for Internationalisation

    /((?<=\s)|(?<=^))(((\d{1,3})((,\d{3})|(\.\d{3}))*(((?<=(,\d{3}))(\.\d{2}))|((?<=(\.\d{3}))(,\d{2}))|((?

    Matches

    14.23
    14,23
    114,114,114.23
    114.114.114,23
    

    Doesn't match

    14.
    114,114,114,23
    114.114.144.23
    ,
    .
    
    

提交回复
热议问题