fork(11) download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String example = " if (ans(this) >= ans({1,2}) and (cond({3,4}) or ans(this) <= ans({5,6})), 7, 8) and {111} > {222} or ans(this) = \"hello my friend and or \" and(cond({1,2}) $1 123 ";
  11. String rx = "\\s*\\b(and|or|if)\\b\\s*|(\"[^\"]*\")|(\\s+)";
  12. Matcher m = Pattern.compile(rx).matcher(example);
  13. example = m.replaceAll(r -> r.group(3) != null ? "" : r.group(2) != null ? r.group(2) : " " + r.group(1) + " ").trim();
  14. System.out.println( example );
  15. //E: if (ans(this)>=ans({1,2}) and (cond({3,4}) or ans(this)<=ans({5,6})),7,8) and {111}>{222} or ans(this)="hello my friend and or " and(cond({1,2})$1123
  16. //C:
  17. }
  18. }
Success #stdin #stdout 0.12s 36292KB
stdin
Standard input is empty
stdout
if (ans(this)>=ans({1,2}) and (cond({3,4}) or ans(this)<=ans({5,6})),7,8) and {111}>{222} or ans(this)="hello    my friend and  or  " and (cond({1,2})$1123