fork(3) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String text = "(слива) какие-то другие слова [яблоко], еще слова {груша}.";
  11. Pattern pattern = Pattern.compile("[(\\[{](.*?)[)\\]}]");
  12. Matcher matcher = pattern.matcher(text);
  13. List<String> lst = new ArrayList<>();
  14. while (matcher.find()){
  15. lst.add(matcher.group(1));
  16. }
  17. System.out.println(lst);
  18. }
  19. }
Success #stdin #stdout 0.06s 2841600KB
stdin
Standard input is empty
stdout
[слива, яблоко, груша]