fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.util.regex.*;
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. List<String> res = new ArrayList<String>();
  10. Pattern p = Pattern.compile("([&]{1,2}|=>?| +)");
  11. String s = "s=a&=>b";
  12. Matcher m = p.matcher(s);
  13. int pos = 0;
  14. while (m.find()) {
  15. if (pos != m.start()) {
  16. res.add(s.substring(pos, m.start()));
  17. }
  18. res.add(m.group());
  19. pos = m.end();
  20. }
  21. if (pos != s.length()) {
  22. res.add(s.substring(pos));
  23. }
  24. for (String t : res) {
  25. System.out.println("'"+t+"'");
  26. }
  27. }
  28. }
Success #stdin #stdout 0.02s 245632KB
stdin
Standard input is empty
stdout
's'
'='
'a'
'&'
'=>'
'b'