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 text = " ~*_abc~xyz~ ~123~";
  11. Pattern p = Pattern.compile("(?=(~[^\\s~]+~))");
  12. Matcher m = p.matcher(text);
  13. List<String> res = new ArrayList<>();
  14. while(m.find()) {
  15. res.add(m.group(1));
  16. }
  17. System.out.println(res);
  18. }
  19. }
Success #stdin #stdout 0.12s 34000KB
stdin
Standard input is empty
stdout
[~*_abc~, ~xyz~, ~123~]