import java.util.regex.Matcher; import java.util.regex.Pattern; public class MainClass { public static void main(String args[]) { Pattern p = Pattern.compile("\\d"); Matcher m1 = p.matcher("55"); Matcher m2 = p.matcher("fdshfdgdfh"); System.out.println(m1.pattern() == m2.pattern()); } }