fork(1) download
  1. /*
  2. Separar expresión matemática con expresiones regulares en Java
  3. https://es.stackoverflow.com/q/127195/127
  4. */
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. //variables
  11. final String texto = "1000000.315+5.8/(6.0+1-8*2.0)";
  12. final String regex = "(?=[-+*/()])|(?<=[-+*/()])";
  13. final String[] resultado;
  14.  
  15. //split
  16. resultado = texto.split(regex);
  17.  
  18. //imprimimos 1 por 1
  19. for (String item : resultado) {
  20. System.out.println(item);
  21. }
  22. }
  23. }
Success #stdin #stdout 0.1s 27828KB
stdin
Standard input is empty
stdout
1000000.315
+
5.8
/
(
6.0
+
1
-
8
*
2.0
)