判斷正負實數
- [+-]?((\d+\.?\d*)|(\.\d+))
- https://regex101.com/r/zB7vV3/27
String pattern = "[+-]?((\\d+\\.?\\d*)|(\\.\\d+))"; // Create a Pattern objectPattern r = Pattern.compile(pattern);// Now create matcher object.Matcher m = r.matcher(expression);int x = 0;while (m.find()) { Log.d("[FIND]", x + ":-->" + m.group(x++));} return m.find();
判斷整數加減乘除
- ^(\d+[\+\-\*\/]{1})+\d+$
- https://regex101.com/r/zB7vV3/28
規則
expression.replaceAll("^(0+)", "");
或
expression.replaceFirst("^0+", "")
沒有留言:
張貼留言