Regular expression. Learn more here: https://docs.oracle.com/javase/tutorial/essential/regex/
The easiest way of calling it is using String.matches(String regex)
If you want to check the same regular expression more often, it's better to precompile it and use a Pattern.
A typical invocation sequence is then
Pattern p = Pattern.compile(".*A.*B.*"); // you keep this stored for re-use
Matcher m = p.matcher("BARBARIAN");
boolean b = m.matches();
There is a good Online Regex Tester and Debugger tool, where you can check your regular expression.
.*instead of%and.instead of_