fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. String s = "|Hello all, | morning [name|address] |";
  10. Pattern pattern = Pattern.compile("(?:\\([^()]*\\)|\\[[^\\]\\[]*]|[^|])+");
  11. Matcher matcher = pattern.matcher(s);
  12. while (matcher.find()){
  13. System.out.println(matcher.group().trim());
  14. }
  15. }
  16. }
Success #stdin #stdout 0.09s 51788KB
stdin
Standard input is empty
stdout
Hello all,
morning [name|address]