Java tutorial
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { String input = " javaId=2 test test javaId=33432. javaId=100"; Pattern p = Pattern.compile("(javaId=)(\\d+)"); Matcher m = p.matcher(input); StringBuffer result = new StringBuffer(); while (m.find()) { System.out.println("Masking: " + m.group(2)); m.appendReplacement(result, m.group(1) + "***masked***"); } m.appendTail(result); System.out.println(result); } }