2014-11-06 59 views
0

我可以看到下面的代碼中的正則表達式...正則表達式,如果塊

if (amount.matches("[-+]?[0-9]*\\.?[0-9]+")) return true; 

現在我的查詢是什麼這個正則表達式表示量 應該是數字,什麼驗證它會檢查

+0

它只是檢查'amount'變量是否與一個帶符號的十進制數字匹配。 – anubhava 2014-11-06 06:10:02

+0

@anubhava請你分享它的例子,例如數字將是-2345.76像這樣 – 2014-11-06 06:11:15

+1

它匹配以下任何數字:'-2345.76','-2345','+ 2345.76','+ 2345','' 2345','-76','+ .76','.76' – anubhava 2014-11-06 06:15:23

回答

1

你的正則表達式是這樣的:

 "[-+]?[0-9]*\\.?[0-9]+" 
[-+]? --> either a `+` or `-` or nothing. Followed by 
[0-9]* --> any number of digits (* implies greedy check). Followed by 
`\\.?` --> 0 or 1 `.` (matched literally.). Followed by 
[0-9]+ --> one or more digits 

demo here