import java.util.regex.*;

public class regex3 
{
    public static void main(String[] args) 
    {
        String format1 = "\\d\\d\\d-\\d\\d-\\d\\d\\d\\d";
        String string1 = "123121234"; 
        String string2 = "123-12-1234";
        String string3 = "0123-12-1234567";
        boolean OK; 

        Pattern p1 = Pattern.compile(format1);       
        Matcher m1 = p1.matcher(string1);                           
        OK = m1.find();                                     
        System.out.println(format1 + "\t found in:\t " + string1 + " --> " + OK);   

        m1.reset(string2);                                      //reassign a new text string                            
        OK = m1.find();                                     
        System.out.println(format1 + "\t found in:\t " + string2 + " --> " + OK);   

        m1.reset(string3);                                      //reassign a new text string                            
        OK = m1.find();                                     
        System.out.println(format1 + "\t found in:\t " + string3 + " --> " + OK);   

        OK = m1.matches();                                      
        System.out.println(format1 + "\t exact matches:\t " + string3 + " --> " + OK);  

        System.out.println();

        String format2 = "^[^0-9][A-z0-9_]+(\\.[A-z0-9_]+)*@[A-z0-9_]+(\\.[A-z0-9_]+)*\\.[A-z]{2,4}$";
        String string6 = "blahblah@blahblah"; 
        String string7 = "sam1sultan@gmail.com";
        String string8 = "sam.sultan@nyu.edu";

        Pattern p2 = Pattern.compile(format2);       
        Matcher m2 = p2.matcher(string6);                           
        OK = m2.matches();                                      
        System.out.println(string6 + "\t is valid email --> " + OK);    

        m2.reset(string7);                                      //reassign a new text string                            
        OK = m2.matches();                                      
        System.out.println(string7 + "\t is valid email --> " + OK);    

        m2.reset(string8);                                      //reassign a new text string                            
        OK = m2.matches();                                      
        System.out.println(string8 + "\t is valid email --> " + OK);    
    }       
}