fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7.  
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String regex = "\\[\\[[^|]+\\|(.+?)]]";
  13. String string = "Some random text about [[Roman Empire|the romans]] test Some random text about [[Another Empire|the romans 2]]";
  14.  
  15. Pattern pattern = Pattern.compile(regex);
  16. Matcher matcher = pattern.matcher(string);
  17.  
  18. while (matcher.find()) {
  19. System.out.println(matcher.group(1));
  20. }
  21. }
  22. }
Success #stdin #stdout 0.09s 48508KB
stdin
Standard input is empty
stdout
the romans
the romans 2