import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.regex.*;

class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String line = "add, $temp4, $temp40, 42";
        String to = "register1";
        String from = "$temp4";
        String outString;

        from = "(?<!\\w)" + Pattern.quote(from) + "(?!\\w)";

        outString = line.replaceAll(from, to);
        System.out.println(outString);
	}
}