fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. final String string = "Select a, CASE \n"
  13. + "WHEN 1 \n"
  14. + "THEN \n"
  15. + " CASE some text\n"
  16. + " WHEN 2 THEN A \n"
  17. + " END \n"
  18. + "END";
  19. String regex = "(?i)(\\bcase\\s+)\\S((?!\\bCASE\\s).)*?(?=\\s+when)";
  20. String repl = string.replaceAll(regex, "$1var");
  21. System.out.println(repl);
  22. }
  23. }
Success #stdin #stdout 0.08s 52272KB
stdin
Standard input is empty
stdout
Select a, CASE 
WHEN 1 
THEN 
   CASE var
     WHEN 2 THEN A 
   END 
END