fork(2) download
  1. import java.util.*;
  2. import java.util.stream.*;
  3. import java.util.regex.*;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. String text = "12 + (ab-bc*3)";
  10. List<String> results = Pattern.compile("\\p{Punct}|\\w+").matcher(text)
  11. .results()
  12. .map(MatchResult::group)
  13. .collect(Collectors.toList());
  14. System.out.println(results);
  15. }
  16. }
Success #stdin #stdout 0.11s 34164KB
stdin
Standard input is empty
stdout
[12, +, (, ab, -, bc, *, 3, )]