The below quantifier is used to replace anything that contains 1 or more h and then 0 or more i and then a j
Note i* here means 0 or more i and h+ means 1 or more h
System.out.println(alphaNumeric.replaceAll("h+i*j", "X"));