fork download
  1. import java.lang.*;
  2. import java.util.*;
  3. import java.util.regex.Pattern;
  4. import java.util.regex.Matcher;
  5.  
  6. /* Name of the class has to be "Main" only if the class is public. */
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. HashMap<String,String> m = new HashMap<String,String>();
  12. String regex = "\\G\\|\\|\\h*(.*?)\\h*\\|\\h*(\\[[^\\]\\[]*\\]|.*?)\\h*\\|\\R?";
  13. String string = "|| Responsible | abc|\n"
  14. + "|| Departement | def |\n\n"
  15. + "|| SystemA Username | ghi |\n"
  16. + "|| Operation | READ |\n"
  17. + "|| Page | [Example|http://w...content-available-to-author-only...e.com] |\n\n"
  18. + "|| SystemB Username | jhk |\n"
  19. + "|| Operation | WRITE |\n"
  20. + "|| App | helloWorld |";
  21.  
  22. Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  23.  
  24. for (String s : string.split("(?m)^\\s*$")) {
  25. Matcher matcher = pattern.matcher(s.trim());
  26. while (matcher.find()) {
  27. m.put(matcher.group(1), matcher.group(2));
  28. }
  29. }
  30.  
  31. for(Map.Entry<String, String> entry : m.entrySet()){
  32. System.out.println(entry.getKey() + " --> " + entry.getValue());
  33. }
  34. }
  35. }
Success #stdin #stdout 0.12s 51024KB
stdin
Standard input is empty
stdout
App --> helloWorld
SystemB Username --> jhk
Departement --> def
SystemA Username --> ghi
Page --> [Example|http://w...content-available-to-author-only...e.com]
Operation --> WRITE
Responsible --> abc