公告
财富商城
积分规则
提问
发文
2018-12-31 08:58发布
浪荡孟婆
I can't figure out how to construct a regex for the example values:
123,456,789 -12,34 1234 -8
Could you help me?
Try this:
^-?[\d\,]+$
It will allow an optional - as the first character, and then any combination of commas and digits.
-
For the examples:
^(-)?([,0-9])+$
It should work. Implement it in whichever language you want.
^-? # start of line, optional - (\d+ # any number of digits |(\d{1,3}(,\d{3})*)) # or digits followed by , and three digits ((,|\.)\d+)? # optional comma or period decimal point and more digits $ # end of line
In java, You may use java.util.Scanner with its useLocale method
java.util.Scanner
useLocale
Scanner myScanner = new Scanner(input).useLocale( myLocale) isADouble = myScanner.hasNextDouble()
boxValue = boxValue.replace(/[^0-9\.\,]/g, "");
This RegEx will match only digits, dots, and commas.
^-?\d{1,3}(,\d{3})*(\.\d\d)?$|^\.\d\d$
Allows for:
1 12 .99 12.34 -18.34 12,345.67 999,999,999,999,999.99
最多设置5个标签!
Try this:
It will allow an optional
-
as the first character, and then any combination of commas and digits.For the examples:
It should work. Implement it in whichever language you want.
In java, You may use
java.util.Scanner
with itsuseLocale
methodTry this:
This RegEx will match only digits, dots, and commas.
Try this:
Allows for: