fork download
  1. import java.util.*;
  2. import java.util.regex.*;
  3.  
  4. class Ideone
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String input = "45 + 31.05 * 110 @ 54";
  9. String masterOfRegexes = "[0-9]+(?:\\.[0-9]+)?|[+]|[*]|[0-9]+|(\\S)";
  10. Pattern pattern = Pattern.compile(masterOfRegexes);
  11. Matcher matcher = pattern.matcher(input);
  12. List<String> result = new ArrayList<>();
  13. while (matcher.find()){
  14. if (matcher.group(1) != null) {
  15. throw new Exception("Unknown char detected!");
  16. } else {
  17. result.add(matcher.group());
  18. }
  19. }
  20. System.out.println(result);
  21. }
  22.  
  23.  
  24. }
Runtime error #stdin #stdout #stderr 0.1s 48124KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.Exception: Unknown char detected!
	at Ideone.main(Main.java:15)