fork(1) 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. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. final String regex = "(?:\\{\\{[^|]*|\\G(?!^))(?=[^\\}]*\\}})\\|([^=]+)=([^|\\}]+)";
  12. final String string = "{{cite web |url=http://w...content-available-to-author-only...a.lu |title=Gouvernement du Canada -\n"
  13. + " Government of Canada |publisher= |accessdate=20 February 2015}}\n\n\n"
  14. + "{{cite book\n"
  15. + "|url=https://books.google.com/?id=U3L6H8eOIb0C&pg=PA117&dq=Estonia+and+Luxembourg#PPA118,M1\n"
  16. + "|title=The Radical Right in Interwar Estonia |publisher=\n"
  17. + "|accessdate=20 February 2015 |isbn=9780312225988 |last1=Kasekamp\n"
  18. + "|first1=Andres}}";
  19.  
  20. final Pattern pattern = Pattern.compile(regex);
  21. final Matcher matcher = pattern.matcher(string);
  22.  
  23. while (matcher.find()) {
  24. System.out.println(matcher.group(1).replaceAll("\\R", "") + " = " + matcher.group(2).replaceAll("\\R+", ""));
  25. }
  26. }
  27. }
Success #stdin #stdout 0.12s 36548KB
stdin
Standard input is empty
stdout
url = http://w...content-available-to-author-only...a.lu 
title = Gouvernement du Canada - Government of Canada 
publisher =  
accessdate = 20 February 2015
url = https://books.google.com/?id=U3L6H8eOIb0C&pg=PA117&dq=Estonia+and+Luxembourg#PPA118,M1
title = The Radical Right in Interwar Estonia 
publisher = 
accessdate = 20 February 2015 
isbn = 9780312225988 
last1 = Kasekamp
first1 = Andres