fork download
  1. import java.util.*;
  2. import java.util.regex.Pattern;
  3. import static java.util.stream.Collectors.*;
  4.  
  5. class Ideone {
  6. public static void main (String[] args) {
  7. String data = "John Adams (Backend developer) Bob Scott (Frontend developer) (UI/UX designer) Alex Walker (Network engineer)";
  8. Map<String, List<String>> skills = Pattern.compile("(.*?) \\((.*?)\\)(?! \\() ?").matcher(data)
  9. .results().collect(toMap(mr -> mr.group(1), mr -> Arrays.asList(mr.group(2).split("\\) \\("))));
  10. skills.forEach((n, s) -> System.out.printf("%s has skills: %s\n", n, String.join(", ", s)));
  11. }
  12. }
Success #stdin #stdout 0.09s 49156KB
stdin
Standard input is empty
stdout
Bob Scott has skills: Frontend developer, UI/UX designer
John Adams has skills: Backend developer
Alex Walker has skills: Network engineer