import java.util.regex.*;


/**
 * Examples that use regular expressions.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class RegularExpressions
{
    /**
     * The entry point of the application.
     *
     * @param args  The command line arguments (which are validated)
     */
    public static void main(String[] args)
    {
//[0
        boolean ok;
        String  s, t, u;

        t = "David Bernstein \n CS149 \n CS159";
        s = "yes";        

        // A search (and Replace) Example:
        //   Replace any whitespace in t with a tab 
        u = t.replaceAll("\\s+", "\t");

        // A Validation Example:
        //   Check if s matches "true", "True", "yes", or "Yes"
        ok = s.matches("[tT]rue|[yY]es");
//]0



//[1
        // A valid phone number consists of an x and 4 digits or
        // 3 digits, a dash or dot, and 4 digits
        
        Matcher validator;        
        Pattern phone;
        phone = Pattern.compile("x\\d\\d\\d\\d|\\d\\d\\d[-.]\\d\\d\\d\\d");

        for (int i=0; i<args.length; i++)
        {
            validator = phone.matcher(args[i]);        
            if (validator.matches())
            {
                System.out.println(args[i]);
            }
        }
//]1
    }
    
}
