fork download
  1. import java.util.regex.*;
  2.  
  3. class Example {
  4.  
  5. public static void main(String[] args) throws Exception
  6. {
  7. String input = "the current time is <start time>00:00:00<end time>. at 00:00:00 there is a firework. Another appearance of 00:00:00.";
  8. String result = input.replaceAll("(?<!<start time>)00:00:00(?!<end time>)", "<start time>00:00:00<end time>");
  9. System.out.println(result);
  10. }
  11. }
Success #stdin #stdout 0.1s 27872KB
stdin
Standard input is empty
stdout
the current time is <start time>00:00:00<end time>. at <start time>00:00:00<end time> there is a firework. Another appearance of <start time>00:00:00<end time>.