// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SmartReplace {
    private final static Pattern p = Pattern.compile("grillmad", Pattern.CASE_INSENSITIVE);
    public static void test(String s) {
        Matcher m = p.matcher(s);
        if(m.find()) {
            System.out.println(s + " after replace: " + m.replaceAll(""));
        } else {
            System.out.println(s + " does not contain grillmad");
        }
    }
    public static void main(String[] args) {
        test("Denne her har grillmad!");
        test("Denne her har GRILLMAD!");
        test("Denne her har gRiLlMaD!");
        test("Denne her har ikke!");
    }
}
