import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Ideone {
	public static void main (String[] args) throws java.lang.Exception {
		Pattern pattern = Pattern.compile("([a-z]+)");
        System.out.println(magic(
        	pattern, 
        	"eee xxx 233 yyy zzz xxx", 
        	x -> "xxx".equals(x) ? "1" : "0"));
	}
    public static String magic(
    		Pattern pattern, 
    		String input, 
    		Function<String, String> fun) {
        Matcher matcher = pattern.matcher(input);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, fun.apply(matcher.group()));
        }
        return sb.toString();
    }
}