fork(1) download
  1. import java.util.*;
  2. import java.util.regex.*;
  3.  
  4. class Test
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String s = "**bold** _italic_ ~strike~ `**code**` **_bold and italic_**";
  9. String rx = "(`[^`]*`)|(\\*\\*|[_~])((?:(?!\\2).)*)\\2";
  10. String prev = "";
  11. do {
  12. prev = s;
  13. s = s.replaceAll(rx, "$1$3");
  14. }
  15. while (!prev.equals(s));
  16. s = s.replaceAll("`([^`]*)`", "$1");
  17. System.out.println(s);
  18. }
  19. }
Success #stdin #stdout 0.1s 48428KB
stdin
Standard input is empty
stdout
bold  italic strike **code** bold and italic