fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. System.out.println(replace(reader.readLine(), reader.readLine(), reader.readLine()));
  15. }
  16.  
  17. static String replace(String source, String from, String to) {
  18. Matcher matcher = Pattern.compile(from).matcher(source);
  19.  
  20. matcher.reset();
  21. boolean result = matcher.find();
  22. if (result) {
  23. do {
  24. System.out.println(matcher.group()+" menyaem na "+to);
  25. matcher.appendReplacement(sb, to);
  26. result = matcher.find();
  27. } while (result);
  28. matcher.appendTail(sb);
  29. return sb.toString();
  30. }
  31. return source;
  32. }
  33. }
Success #stdin #stdout 0.08s 380224KB
stdin
SOSI HUI BIDLO. HUI TVOEI MAMKE I TEBE
[H,U,I]{3}
LEDENEC
stdout
HUI menyaem na LEDENEC
HUI menyaem na LEDENEC
SOSI LEDENEC BIDLO. LEDENEC TVOEI MAMKE I TEBE