fork 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 s = "Bla bla bla [https://google.com|Google] bla bla bla [https://y...content-available-to-author-only...e.com|Youtube]";
  11. String regex = "\\[([^\\]\\[|]*)\\|([^\\]\\[]*)]";
  12. Pattern pattern = Pattern.compile(regex);
  13. Matcher matcher = pattern.matcher(s);
  14. while (matcher.find()){
  15. System.out.println("Match: " + matcher.group(0));
  16. System.out.println("Group 1: " + matcher.group(1));
  17. System.out.println("Group 2: " + matcher.group(2));
  18. }
  19. }
  20. }
Success #stdin #stdout 0.13s 36272KB
stdin
Standard input is empty
stdout
Match: [https://google.com|Google]
Group 1: https://google.com
Group 2: Google
Match: [https://y...content-available-to-author-only...e.com|Youtube]
Group 1: https://y...content-available-to-author-only...e.com
Group 2: Youtube