fork(1) 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 text = "(a) last line % now with comment\n(b) last line with escaped \\% and not treated\n(c) last line withouth any special chars\n(d) last line terminates with %\n(e) last line terminates with escaped \\%\n(f) beginning % but even escaped \\% is ignored";
  11. Pattern p = Pattern.compile("(?<!\\\\)(?:\\\\{2})*%[^\\\\%\r\n]*(?:\\\\[\\w\\W][^\\\\%\r\n]*)*\\z");
  12. Matcher m = p.matcher(text);
  13. if (m.find()) {
  14. System.out.println("Match found!");
  15. }
  16. }
  17. }
Success #stdin #stdout 0.09s 34020KB
stdin
Standard input is empty
stdout
Match found!