fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String line = "add, $temp4, $temp40, 42";
  11. String to = "register1";
  12. String from = "$temp4";
  13. String outString;
  14.  
  15. from = "(?<!\\w)" + Pattern.quote(from) + "(?!\\w)";
  16.  
  17. outString = line.replaceAll(from, to);
  18. System.out.println(outString);
  19. }
  20. }
Success #stdin #stdout 0.09s 27720KB
stdin
Standard input is empty
stdout
add, register1, $temp40, 42