use regex in if statement java

Java
Pattern p = Pattern.compile("a*b");
 Matcher m = p.matcher("aaaaab");
 boolean b = m.matches();
Source

Also in Java: