fork(57) download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Main
  5. {
  6. static void processString(String line)
  7. {
  8. System.out.println("Processing: " + line);
  9. Pattern p = Pattern.compile("\\G(\\w+)=(\\w+);");
  10. Matcher m = p.matcher(line);
  11. int lastMatchPos = 0;
  12. while (m.find()) {
  13. System.out.println(" " + m.group(1) + " - " + m.group(2));
  14. lastMatchPos = m.end();
  15. }
  16. if (lastMatchPos != line.length())
  17. System.out.println(" Invalid string!");
  18. }
  19.  
  20. public static void main(String[] args)
  21. {
  22. processString("name1=gil;name2=orit;");
  23. processString("name1=gil;name2=orit;a");
  24. processString("name1=gil;;name2=orit;");
  25. processString(";name1=gil;name2=orit;");
  26. processString("name1=gil;=name2=orit;");
  27. }
  28. }
Success #stdin #stdout 0.06s 28000KB
stdin
Standard input is empty
stdout
Processing: name1=gil;name2=orit;
  name1 - gil
  name2 - orit
Processing: name1=gil;name2=orit;a
  name1 - gil
  name2 - orit
  Invalid string!
Processing: name1=gil;;name2=orit;
  name1 - gil
  Invalid string!
Processing: ;name1=gil;name2=orit;
  Invalid string!
Processing: name1=gil;=name2=orit;
  name1 - gil
  Invalid string!