/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String s = "<><PALAVRA outrapalavra>palavra</PALAVRA>";
		String parametro = "palavra";
		String replace = "NovaPalavra";
		
		Pattern p = Pattern.compile("<(/?)(.*?)("+parametro+")(.*?)>", Pattern.CASE_INSENSITIVE);
		s = p.matcher(s).replaceAll("<$1$2"+replace+"$4>");
		
		System.out.print(s);
	}
}