import java.util.regex.Matcher; import java.util.regex.Pattern; public class StringProcessor { public static void main(String[] args) { String text = "asd oOsdwe ertyu ghjLK Ewesldk"; String substrings[] = text.split(" "); for (String word : substrings) { String regex = "[AaOrK]"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(word); boolean res = m.find(); System.out.print(" returns: " + " " + res); } } } This code checks the text for the presence of letters [AaOrK]. I need to display only incorrect values.