fork(3) download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String s = "Overtime=true,TransportCosts=1= 1,two, three,Billable=7200";
  11. Map<String,String> map = getAttributes(s);
  12. for (Map.Entry entry : map.entrySet()) {
  13. System.out.println(entry.getKey() + "=" + entry.getValue());
  14. }
  15. //System.out.println(map);
  16. }
  17.  
  18. public static Map<String, String> getAttributes(String attributes) {
  19. Map<String, String> attr = new HashMap<>();
  20. Matcher m = Pattern.compile("(\\w+)=(.*?)(?=,\\w+=|$)").matcher(attributes);
  21. while (m.find()) {
  22. attr.put(m.group(1), m.group(2));
  23. }
  24. return attr;
  25. }
  26. }
Success #stdin #stdout 0.09s 27964KB
stdin
Standard input is empty
stdout
Overtime=true
Billable=7200
TransportCosts=1= 1,two, three